Design APIs with a shared convention: nouns for things, verbs for actions, status codes for outcomes, so callers can guess most of it without reading the docs.
Why use it
Guessable: GET /orders/123 clearly means “fetch order 123”.
Easier collaboration: frontend, mobile, and third parties share one convention.
Easier debugging: the status code tells you whether the client or the server was wrong.
How to do it
1. Paths use nouns (plural), not verbs
Avoid
Prefer
POST /createOrder
POST /orders
GET /getOrder?id=1
GET /orders/1
POST /deleteOrder
DELETE /orders/1
2. Use HTTP verbs for the action
Verb
Meaning
Idempotent?*
GET
Read, no data change
Yes
POST
Create
No
PUT
Full replace
Yes
PATCH
Partial update
Usually not guaranteed
DELETE
Delete
Yes
*Idempotent: repeating the call has the same result as calling once; see Idempotency.
3. Status codes tell the truth
Status
When
200 OK
Read or update succeeded
201 Created
Create succeeded
204 No Content
Success with no body (e.g. delete)
400 Bad Request
Bad request format or parameters
401 Unauthorized
Not signed in
403 Forbidden
Signed in but not allowed
404 Not Found
Resource does not exist
409 Conflict
Conflicts with existing data (e.g. duplicate)
429 Too Many Requests
Rate limited
500
The server itself failed
🧭 Which status code a request should return
📥Request received
↓
Format and parameters OK?
No400 bad request
↓
Signed in?
No401 not signed in
↓
Allowed?
No403 forbidden
↓
Resource exists?
No404 not found
↓
Success200 / 201 created / 204 no content
When the server itself fails, return 500.
4. Nesting for ownership: GET /users/5/orders means user 5’s orders. Keep nesting to at most two levels.
Component comparison
REST
Hand-rolledOpen sourceOpsLow
The most common API style: URLs represent resources, actions such as GET and POST represent operations, and JSON is returned.
Best forThe vast majority of web apps, mini-program backends, publicly exposed APIs.
Avoid whenFrontend page data shapes vary enormously, or services need high-performance internal communication.
Pros
The most universal: frontends, mini-programs and third parties can call it directly
The most tools and documentation, and it can be debugged right in the browser
Can use HTTP caching, with simple and easy-to-understand design rules
Cons
When the data a frontend wants is spread across several endpoints, multiple requests are needed
Endpoint response fields are fixed, so it is easy to return too much or too little data
No unified strong constraints; without team agreement, styles become mixed
GraphQL
Self-hosted open sourceOpen sourceOpsMedium
The frontend writes "which fields I want" itself, and a single endpoint returns exactly that, no more and no less.
Best forProjects with complex pages and many data relationships, where the frontend team wants to control data fetching.
Avoid whenSimple APIs, small teams, or when it must be opened to third parties for quick integration.
Pros
One request can bring back several related pieces of data
The client picks the fields it needs and sends less unused data
The type description comes with it, which helps generate docs and tools
Cons
One query can easily fan out into a large number of database requests
Caching, rate limits, and permissions are all harder than with REST
The team has to learn an extra query language and its tools