REST API URLs should be nouns naming resources (in the plural); the action lives in the HTTP method.
GET, PUT and DELETE are idempotent; POST and PATCH are not by default.
Status codes tell the client what happened: 2xx success, 4xx caller error, 5xx server error.
When you build an API for a mobile app, a website or another service to call, the hardest part is usually not the code but setting conventions so that other people can guess how to use it without asking you.
This article covers three foundational conventions of a REST API running over HTTP: how to name resources in the URL, how to choose an HTTP method, and how to choose the status code you return.
A small caveat: "REST" is an architectural style, not a certified standard. Most APIs called REST in the real world follow only part of that style.
So the practical goal here is consistency and predictability, while the behavior of each method and status code is already well described by the HTTP standard (RFC 9110), so you should follow it.
A resource is a "thing" the API manages: a user, an order, an invoice, an uploaded file. Each resource has an address (a URL). A few common conventions keep addresses readable:
Use nouns, not verbs. /users rather than /getUsers. The action is already expressed by the HTTP method.
Use the plural for collections. /orders is the list of orders, /orders/42 is one specific order. Plural or singular both work, as long as the whole API is consistent.
Nest resources when ownership is clear. /orders/42/items are the line items of order 42.
Do not nest more than two or three levels; past that, give the child resource its own address such as /items/9.
Lowercase, separated by hyphens. /order-items reads better than /OrderItems. Addresses should stay stable over time.
Keep sensitive information out of URLs, because URLs can end up in server logs, proxies and browser history.
Some operations do not look like "create, update, delete a record", for example "cancel an order" or "resend the confirmation email". There are two common approaches.
The first treats the result as a new resource: POST /orders/42/cancellations. The second accepts a "verb" at the end of the path: POST /orders/42/cancel.
The latter is shorter but departs from the noun convention; either is fine, so document it and apply it consistently.
The method says what you want to do with the resource. The HTTP standard (RFC 9110) defines two properties worth remembering:
Safe: the method is read-only and does not change state on the server. GET, HEAD and OPTIONS belong here.
Idempotent: calling it once or several times in a row with the same content leaves the server in the same final state.
GET, HEAD, OPTIONS, PUT and DELETE are idempotent; POST and PATCH are not guaranteed to be by default.
Method
GET
Used to
Read a resource or a list
Example
GET /orders/42
Method
POST
Used to
Create, or trigger an operation
Example
POST /orders
Method
PUT
Used to
Replace a whole resource
Example
PUT /orders/42
Method
PATCH
Used to
Partially modify a resource
Example
PATCH /orders/42
Method
DELETE
Used to
Delete a resource
Example
DELETE /orders/42
A few points that are often confused:
Never change data with GET. Browsers, proxies and crawlers may call GET freely (to warm caches, to preview links).
If GET /orders/42/delete deletes data, you will hit incidents that are very hard to explain.
PUT and PATCH differ. PUT sends the complete new representation of the resource; a missing field may be treated as removed. PATCH sends only what changes.
What does an idempotent DELETE mean? Deleting order 42 twice leaves order 42 gone after both calls.
The second call may return 404; that does not violate idempotency, because the property is about server state, not the returned code.
POST is the "general-purpose" method. Since it is not idempotent by default, retrying a POST on a flaky network can create two orders.
The article Pagination, filtering and sorting in a REST API: offset, cursor and the conventions to agree on continues with how to read lists, while preventing duplicate creation is covered in the last article of this series.
A status code is the three-digit number on the first line of the response. Remember the class first:
2xx: success.
3xx: redirection or "unchanged" (for example 304 Not Modified).
4xx: the caller (client) sent a faulty request.
5xx: the server failed.
The codes used most in APIs:
Code
200 OK
Meaning
Success, with a body
When to use
Successful GET, PUT, PATCH
Code
201 Created
Meaning
A new resource was created
When to use
POST that creates; should include a Location header pointing at the new resource
Code
204 No Content
Meaning
Success, no body
When to use
Successful DELETE
Code
400 Bad Request
Meaning
Syntactically wrong request
When to use
Broken JSON, missing required parameter
Code
401 Unauthorized
Meaning
Not authenticated or credentials wrong
When to use
Token missing or expired
Code
403 Forbidden
Meaning
Authenticated but not allowed
When to use
The user may not view this resource
Code
404 Not Found
Meaning
Not found
When to use
Address or id does not exist
Code
405 Method Not Allowed
Meaning
Method not supported at this address
When to use
DELETE /orders when the API disallows it; should include an Allow header
Code
409 Conflict
Meaning
Conflicts with current state
When to use
Creating a record that violates a unique key
Code
422 Unprocessable Content
Meaning
Syntax is fine but the content is invalid
When to use
Malformed email, negative quantity
Code
429 Too Many Requests
Meaning
Too many calls
When to use
Rate limit exceeded (defined in RFC 6585)
Code
500 Internal Server Error
Meaning
Unexpected server failure
When to use
Unhandled exception
Code
503 Service Unavailable
Meaning
Temporarily cannot serve
When to use
Maintenance, overload
The two most confused pairs are 401 and 403 (401: "I do not know who you are"; 403: "I know you, but you are not allowed") and 400 and 422 (400: the request cannot be read; 422: it can be read but a value is invalid).
Many APIs merge 400 and 422 into one, which is acceptable as long as you are consistent.
Do not return 200 OK with a body like {"error": "..."} for a failure.
Monitoring tools, caches and client libraries all rely on the status code to guess what happened; the wrong code makes everything downstream misread it.
Suppose you create an order and read it back (addresses use the example domain):
POST https://api.example.com/orders
Content-Type: application/json
{"customerId": 7, "items": [{"sku": "A-100", "quantity": 2}]}
A sensible response:
HTTP/1.1 201 Created
Location: https://api.example.com/orders/42
Content-Type: application/json
{"id": 42, "status": "pending"}
After that GET /orders/42 returns 200, DELETE /orders/42 returns 204, and calling GET /orders/42 again returns 404.
This sequence of codes is enough for a client to understand the whole lifecycle without reading anything else.
Name resources with nouns, use the plural consistently, nest at most a few levels.
Let the HTTP method express the action; know which methods are safe and idempotent.
Return status codes of the right class; do not hide errors in a 200 body.
Every convention is a commitment to your API's users. Choose few, choose them clearly, write them down and keep them.