Knowledge

Designing a REST API: naming resources, choosing HTTP methods and picking the right status codes

Updated 2026-11-23 · Present

  • 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.

Introduction

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.

Naming resources

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:

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.

Choosing HTTP methods

The method says what you want to do with the resource. The HTTP standard (RFC 9110) defines two properties worth remembering:

Method Used to Example
GET Read a resource or a list GET /orders/42
POST Create, or trigger an operation POST /orders
PUT Replace a whole resource PUT /orders/42
PATCH Partially modify a resource PATCH /orders/42
DELETE Delete a resource DELETE /orders/42

A few points that are often confused:

Choosing status codes

A status code is the three-digit number on the first line of the response. Remember the class first:

The codes used most in APIs:

Code Meaning When to use
200 OK Success, with a body Successful GET, PUT, PATCH
201 Created A new resource was created POST that creates; should include a Location header pointing at the new resource
204 No Content Success, no body Successful DELETE
400 Bad Request Syntactically wrong request Broken JSON, missing required parameter
401 Unauthorized Not authenticated or credentials wrong Token missing or expired
403 Forbidden Authenticated but not allowed The user may not view this resource
404 Not Found Not found Address or id does not exist
405 Method Not Allowed Method not supported at this address DELETE /orders when the API disallows it; should include an Allow header
409 Conflict Conflicts with current state Creating a record that violates a unique key
422 Unprocessable Content Syntax is fine but the content is invalid Malformed email, negative quantity
429 Too Many Requests Too many calls Rate limit exceeded (defined in RFC 6585)
500 Internal Server Error Unexpected server failure Unhandled exception
503 Service Unavailable Temporarily cannot serve 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.

A small example

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.

Summary

Every convention is a commitment to your API's users. Choose few, choose them clearly, write them down and keep them.

References