A REST API is a way for two programs to talk over HTTP using simple web addresses and standard HTTP methods like GET, POST, PUT and DELETE. The part most people get wrong is that REST is a style, not a protocol: it describes how to arrange resources and requests, while HTTP is the actual set of rules that carries them.

HTTP Is the Transport, REST Is the Design

HTTP is the protocol that moves a request from a client to a server and carries the response back. It defines methods, status codes, headers and the request and response format. REST is an architectural style that says how to use those HTTP features well: name things as resources, use the methods for their intended purpose, and keep each request self-contained.

You can build an HTTP API that is not RESTful, for example by putting every action in the URL path. You can also describe a REST design that runs over something other than HTTP, though HTTP is by far the common case. When someone says "REST API HTTP," they usually mean a web service reached over HTTP that follows REST conventions.

The HTTP Methods a REST API Relies On

Each method signals what the client wants to do with a resource. The table below shows the usual mapping; labels and support can differ by server and by version of the tools you use.

MethodPurposeTypical response
GETRead a resource or a list200 with a body; 404 if missing
POSTCreate a new resource201 with the new item; 400 if the body is invalid
PUTReplace a resource entirely200 or 204; 404 if it does not exist
PATCHUpdate part of a resource200 with the changed item
DELETERemove a resource204 with no body; 404 if already gone

GET and DELETE should not change data in ways the client did not ask for. PUT and DELETE are meant to be repeatable: sending the same request twice leaves the same result. POST usually is not repeatable, which is why retrying a failed POST can create duplicates.

Reading a REST Request and Response

A request has four parts: the method, the URL, the headers and an optional body. The URL points at a resource, such as /users/42/orders. Headers carry metadata like Content-Type: application/json and Accept: application/json. The body holds data for POST, PUT and PATCH.

The response has a status code, headers and usually a body. Status codes fall into families: 2xx means success, 3xx means a redirect, 4xx means the client made a mistake, and 5xx means the server failed. A 200 means OK, 201 means created, 204 means success with no content, 400 means a bad request, 401 means not authenticated, 403 means not allowed, 404 means not found, and 500 means a server error.

JSON is the common body format because it is readable and widely supported. A single user might come back as {"id": 42, "name": "Sam", "active": true}. A list usually returns an array, sometimes wrapped with paging details.

Resources, URLs and Statelessness

REST treats everything as a resource with a stable address. Use nouns in URLs, not verbs: /orders/7 rather than /getOrder?id=7. Collections sit at one path and single items at a path with an identifier, so /orders lists orders and /orders/7 returns one.

Each request should carry everything the server needs to answer it. The server should not rely on remembering the previous request. That is what statelessness means in practice: authentication tokens, filters and paging details travel with every call. It makes services easier to scale because any server can handle any request.

A common misconception is that REST requires JSON. It does not. REST is about resources and HTTP methods; the body format is a separate choice, and some APIs return XML or plain text.

Creating and Reading an Order

Suppose a shop exposes /orders. To create an order, the client sends a POST with a JSON body:

  1. Send POST /orders with Content-Type: application/json and a body like {"item": "tea", "quantity": 2}.
  2. The server stores the order and returns 201 Created with a Location header pointing to /orders/7.
  3. To read it back, send GET /orders/7. A 200 OK returns the order; a 404 Not Found means the ID is wrong or the order was removed.
  4. To change the quantity, send PATCH /orders/7 with {"quantity": 3}. A 200 OK returns the updated order.
  5. To cancel it, send DELETE /orders/7. A 204 No Content confirms removal.

If the same POST is sent twice because the first response was lost, two orders may be created. That is why clients often send an idempotency key in a header so the server can recognise a repeat.

Status Codes and Errors You Will Meet

Status codes tell you what happened without reading the body. A 400 usually means the JSON was malformed or a required field was missing. A 401 means the request lacked valid credentials; a 403 means the credentials were valid but the action is not allowed. A 404 means the resource is not there. A 429 means too many requests were sent and you should slow down. A 500 means the server hit an unexpected problem.

Error bodies often include a code and a message, such as {"error": "invalid_quantity", "message": "quantity must be 1 or more"}. Read the message before changing the request, because guessing wastes calls.

Rate limits are common. If you see a 429, wait before retrying, and check the response headers for how long to wait. Retrying a failed POST without an idempotency key can duplicate data.

Where REST APIs Fit Alongside Other Styles

REST is not the only HTTP style. GraphQL sends queries to one endpoint and lets the client ask for exact fields. gRPC uses its own protocol and is common for internal services. Webhooks push events to a URL you provide. REST remains common because it maps cleanly onto HTTP and is easy to test with a browser or a command-line tool.

When you read API documentation, look for the base URL, the authentication method, the list of resources, the methods each resource supports, the status codes and any rate limits. Those five details let you make a first working call. Test with a single GET before writing code, then add POST and error handling.

Does REST require HTTPS?

REST does not require HTTPS, but any API that carries credentials or personal data should use it. HTTP sends data in plain text, so anyone on the network path can read it.

What does idempotent mean for an API?

An idempotent request can be repeated without changing the result beyond the first time. GET, PUT and DELETE are meant to be idempotent; POST usually is not. That difference matters when you retry after a timeout.

Why do some APIs return 200 with an error inside the body?

Some older APIs always return 200 and put success or failure in the body. This makes error handling harder. Prefer APIs that use status codes, and read the documentation so you know which pattern you are dealing with.