The five classes
| Class | Meaning | Typical use |
|---|---|---|
| 1xx | Informational | Protocol switching, early hints, continue |
| 2xx | Success | The request was understood and accepted |
| 3xx | Redirection | The client must take further action |
| 4xx | Client error | The request is invalid, unauthorized or impossible |
| 5xx | Server error | The server failed to fulfill a valid request |
Codes people actually use
Most APIs live on a small set: 200, 201, 204, 301, 304, 400, 401, 403, 404, 409, 422, 429, 500, 502, 503. The rest exist for specific protocol features and are rarely seen outside them.
409 Conflict— uniqueness or state conflict, common in REST APIs.422 Unprocessable Content— valid syntax, invalid semantics (popularized by Rails).428 Precondition Required— forces conditional requests to avoid lost updates.451 Unavailable For Legal Reasons— blocked by legal demand, not by the server.
Rules of thumb
- Use the most specific code that still tells the client what to do next.
- Do not return 200 with
{"error": ...}; it breaks monitoring and client libraries. - 4xx means the client should change the request; 5xx means retrying may help (with backoff).
- Include a machine-readable error body, ideally
application/problem+json(RFC 9457).