REST APIs Explained with Simple Examples

By Sajid Hussain · Published November 2026

Illustration for REST APIs Explained with Simple Examples
Advertisement space (Revbid ad unit goes here)

An API lets one program talk to another. When a weather app shows today’s forecast, it is calling an API that returns the data.

How REST works

REST uses normal web addresses and four main methods: GET to read, POST to create, PUT to update and DELETE to remove. The server replies with data, usually in JSON, and a status code such as 200 for success or 404 for not found.

Calling an API

In JavaScript use fetch, and in Python use the requests library. Send the request, check the status code and then read the JSON. Always handle errors, because networks fail.

Keeping it safe

Many APIs need a key. Never put a secret key in public front-end code or on GitHub. Store keys in environment variables and call the API from your server instead.

Illustration for REST APIs Explained with Simple Examples
Illustration: REST APIs Explained with Simple Examples

Understanding requests and responses

Every API call has two parts. The request says what you want: the address, the method and sometimes extra data or headers. The response contains a status code and the data. Codes starting with 2 mean success, codes starting with 4 mean you made a mistake, such as 401 for missing login or 404 for a wrong address, and codes starting with 5 mean the server has a problem. Learning these groups helps you debug quickly.

Reading JSON

Most APIs return JSON, a simple text format made of keys and values. A weather API might return the city name, the temperature and a list of daily forecasts. In JavaScript you turn the response into an object with the json method, and in Python the requests library does the same. Then you pick the values you need, such as the temperature, and show them on the page. Always check that a value exists before using it, because some responses leave fields empty.

Designing your own API

Once you can use APIs, try building one. Choose clear names for your addresses, for example slash products for a list and slash products slash 5 for one item. Use the right method for each action, return helpful error messages and keep the structure of your answers consistent. Frameworks such as Express for JavaScript and Flask or FastAPI for Python let you create a working API in under an hour.

Rate limits and good manners

Public APIs limit how many requests you can send each minute. If you send too many, the server blocks you with a 429 error. Cache results that do not change often, send requests only when needed and read the documentation to learn the limits. If a request fails, wait a moment and try again instead of repeating it instantly in a loop.

Testing and documentation

Use a free tool such as Postman or your browser to test requests before you write code. This separates problems with the API from problems in your program. Good APIs also come with documentation that lists every address, the data it needs and an example response. When you build your own, write documentation too, because other developers, and your future self, will depend on it.

Practice projects

Build a currency converter with a free exchange-rate API, a weather dashboard for your city, or a quote-of-the-day page. Each project teaches you to read documentation, send requests, handle errors and display results. After that, combine two APIs in one app, for example a map and a weather service, and you will already be working like a professional developer.

Advertisement space (Revbid ad unit goes here)

Back to home

Advertisement space (Revbid ad unit goes here)