HTTP status codes
Categories
Section titled “Categories”| Range | Meaning | Used for |
|---|---|---|
| 1xx | Informational | Protocol switching, 100 Continue |
| 2xx | Success | The request worked |
| 3xx | Redirection | Cache, moved resource, not modified |
| 4xx | Client error | Bad input, missing auth, wrong URL |
| 5xx | Server error | Bug, dependency failure, overload |
The codes that matter
Section titled “The codes that matter”| Code | Name | When to use |
|---|---|---|
| 200 | OK | Successful GET, PUT, PATCH, or POST that returns a body |
| 201 | Created | Resource created; include a Location header |
| 202 | Accepted | Work queued; return a job URL to poll |
| 204 | No Content | Success with no body, e.g. DELETE |
| 301 | Moved Permanently | Permanent URL change; clients cache it |
| 302 | Found | Temporary redirect (often login flows) |
| 304 | Not Modified | Conditional request hit a valid ETag |
| 307 | Temporary Redirect | Like 302 but preserves the method |
| 308 | Permanent Redirect | Like 301 but preserves the method |
| 400 | Bad Request | Malformed syntax or invalid input |
| 401 | Unauthorized | Missing or invalid credentials (really “unauthenticated”) |
| 403 | Forbidden | Authenticated but not allowed |
| 404 | Not Found | Resource does not exist, or you hide its existence |
| 405 | Method Not Allowed | Wrong verb for this route; send Allow |
| 409 | Conflict | State conflict, duplicate key, concurrent edit |
| 410 | Gone | Resource existed and was permanently removed |
| 412 | Precondition Failed | If-Match / If-Unmodified-Since failed |
| 422 | Unprocessable Entity | Syntactically valid but semantically invalid |
| 429 | Too Many Requests | Rate limited; send Retry-After |
| 500 | Internal Server Error | Unexpected server bug |
| 502 | Bad Gateway | Upstream returned an invalid response |
| 503 | Service Unavailable | Overloaded or in maintenance; send Retry-After |
| 504 | Gateway Timeout | Upstream timed out |
Choosing between the confusing ones
Section titled “Choosing between the confusing ones”| Situation | Code |
|---|---|
| No token at all | 401 |
| Valid token, wrong role | 403 |
| Validation error on a JSON body | 422 (or 400) |
| Duplicate email on signup | 409 |
| Unknown ID in the URL | 404 |
| Rate limit exceeded | 429 |
| Server is down for maintenance | 503 |
| Client sent a huge payload | 413 |
| Unsupported content type | 415 |
API design notes
Section titled “API design notes”- Use
201with aLocationheader when creating a resource. - Use
202for async jobs and expose a status endpoint. - Use
429withRetry-Afterrather than silently dropping requests. - Use
409for optimistic-locking conflicts (If-Match). - Do not return
200with{ "error": ... }. Use the status line. - Do not leak stack traces or SQL errors in
500responses. - For bulk operations, return a per-item result with an appropriate top-level status.