A REST API operation is a single action you ask a server to perform on a resource, and it is defined by two things: the HTTP method (GET, POST, PUT, PATCH, DELETE) and the URL of the resource. The method tells the server what kind of action you want; the URL tells it which thing you want the action applied to. Everything else — headers, request bodies, status codes — exists to carry the details of that one request and report back what happened.
What the Five Methods Do
REST maps each common operation onto a standard HTTP method, so a client can predict what a request will do before reading any documentation. The mapping is the backbone of the whole style.
- GET reads a resource or a collection. It should never change anything on the server, so it is safe to repeat.
- POST creates a new resource inside a collection, or triggers an action. Repeating it usually creates a second resource.
- PUT replaces a resource entirely with the representation you send. Sending the same PUT twice leaves the same result.
- PATCH changes part of a resource, sending only the fields you want to alter.
- DELETE removes a resource. A second DELETE on the same URL typically returns a not-found response.
Two properties follow from this design. GET, PUT and DELETE are idempotent: repeating them produces the same server state as doing them once. POST is not, which is why a dropped connection during a POST leaves you unsure whether the resource was created.
Reading the URL and Status Code
The URL names the resource, and its shape tells you what kind of operation you are looking at. A path like /orders points at a collection; /orders/1042 points at one member of it; /orders/1042/items points at a sub-collection belonging to that order. Nouns in the path, verbs in the method — that is the convention, and it keeps URLs stable while behaviour changes.
The status code is the server's short report. The families matter more than the individual numbers:
- 2xx means the operation succeeded. 200 carries a body, 201 confirms a creation and usually includes a Location header, 204 confirms success with no body.
- 3xx means the resource moved or you need to follow a redirect.
- 4xx means the request itself was wrong: 400 for malformed input, 401 for missing or bad credentials, 403 for valid credentials without permission, 404 for a resource that does not exist, 409 for a conflict such as a duplicate, 422 for input that is well-formed but invalid.
- 5xx means the server failed while the request was valid. Retrying a 503 after a short wait is reasonable; retrying a 400 is not.
An Example with Real Values
Suppose a small shop exposes an orders resource. A client wants to create an order, then correct one field, then remove it. Here is the sequence, with the numbers that make each step checkable.
- Create. Send
POST /orderswith a JSON body containing{"customer": "A. Patel", "items": 3, "total": 47.50}. The server replies 201 Created with aLocation: /orders/1042header. The new resource now lives at that URL. - Read it back. Send
GET /orders/1042. The reply is 200 OK and the body matches what you sent, plus a server-assignedidof 1042 and acreatedtimestamp. - Correct one field. The customer's item count was wrong. Send
PATCH /orders/1042with{"items": 2}. The reply is 200 OK, and a follow-up GET showsitems: 2whiletotalis unchanged. - Remove it. Send
DELETE /orders/1042. The reply is 204 No Content. A second DELETE returns 404 Not Found, which is correct: the resource is gone.
Notice that no step needed a special verb in the URL. The method carried the intent, the path carried the target, and the status code carried the outcome. If the create step had failed validation — say items was sent as -1 — the expected reply would be 422 with a body explaining which field was rejected.
Headers and Bodies Carry the Details
Headers describe the request rather than the resource. Content-Type: application/json tells the server how to parse the body; Accept: application/json tells it what you can read back; an Authorization header carries credentials. A request body is used with POST, PUT and PATCH, and is normally omitted for GET and DELETE.
One common misconception is that PUT and PATCH are interchangeable. They are not. PUT means “here is the complete new version of this resource” — fields you leave out may be cleared or reset to defaults. PATCH means “here are the changes” — fields you leave out stay as they are. Sending a partial body with PUT is a frequent cause of silently wiped data, so check which one the endpoint expects before you write the call.
Checking an Operation Before You Trust It
When you are unsure what an endpoint does, three checks settle it quickly. First, read the method: GET should never modify state, so if a GET appears to change something, treat that as a design warning. Second, send the same request twice and compare the results — an idempotent operation leaves the resource identical, while a POST will usually create a duplicate. Third, look at the status code on a deliberately bad request: a 400 or 422 with a field-level message tells you the server validates input, which is a good sign it will also protect you from malformed data.
If a request fails, work down the status families in order. A 401 means fix your credentials, not your body. A 403 means the credentials are fine but the account lacks permission. A 404 can mean the URL is wrong or the resource was deleted. A 409 usually means someone else changed the resource first, so re-read it and try again. A 5xx is the server's problem, and a short wait before one retry is reasonable — but never retry a POST blindly, or you may create the resource twice.
Does a GET request ever change data?
It should not. A well-built API keeps GET read-only so that browsers, caches and retries can repeat it safely. If a GET appears to modify something, treat it as a bug and use the documented method instead.
What is the difference between 401 and 403?
A 401 means the server does not know who you are — the credentials are missing or invalid. A 403 means it knows who you are but you are not allowed to do this. Fixing a 401 means fixing your login; fixing a 403 means asking for permission.
Should a DELETE return the deleted resource?
Either is acceptable. Many APIs return 204 with no body; others return 200 with the removed representation so the client can confirm what was deleted. Check the endpoint's documentation rather than assuming.
Why does my PATCH return 200 but nothing changes?
The most common cause is a field name the server does not recognise, which it may ignore silently. Compare your field names against a GET of the same resource, and check whether the endpoint expects a different content type.