The Plain Picture#
Grades on a report: A means good, F means failed. But you also want to know whose fault a failure is. "You filled the form in wrong" (your problem) is very different from "our office is flooded" (their problem).
The Real Names#
Every response has a 3-digit status code. The first digit is the family:
1xx informational "hold on" rare in practice
2xx success "done"
3xx redirection "look over there instead"
4xx client error "YOU sent something wrong" → fix the request; retrying won't help
5xx server error "WE failed" → maybe retry laterThe ones you must know#
| Code | Name | When |
|---|---|---|
| 200 | OK | success, with a body |
| 201 | Created | a POST created something (return where it lives in Location) |
| 204 | No Content | success, nothing to return (common for DELETE) |
| 301 / 308 | Moved Permanently | the resource moved forever; update your links (308 keeps the method) |
| 302 / 307 | Found / Temporary Redirect | temporarily elsewhere (307 keeps the method) |
| 304 | Not Modified | "your cached copy is still good" (Ch 8) |
| 400 | Bad Request | malformed request |
| 401 | Unauthorized | not logged in — really means "unauthenticated" (Authentication and Authorization (coming soon)) |
| 403 | Forbidden | logged in, but not allowed |
| 404 | Not Found | no such resource |
| 405 | Method Not Allowed | e.g. DELETE on something that only allows GET |
| 409 | Conflict | clashes with the current state (e.g. username taken, edit conflict) |
| 422 | Unprocessable Content | well-formed but invalid data — FastAPI's default for validation errors |
| 429 | Too Many Requests | rate limited; slow down (see Retry-After header) |
| 500 | Internal Server Error | the server's code crashed |
| 502 | Bad Gateway | a proxy/load balancer got a bad reply from the server behind it (Ch 12) |
| 503 | Service Unavailable | overloaded or down for maintenance |
| 504 | Gateway Timeout | a proxy/load balancer gave up waiting for the server behind it |
Gotchas
401 vs 403 is a favourite interview question: 401 = "who are you?", 403 = "I know who you are, and no."
502 vs 504: both come from a proxy in front of your app. 502 = your app replied with garbage or reset the connection (often: it crashed or restarted). 504 = your app was too slow. Neither means the proxy is broken.
Returning
200with{"error": "..."}in the body breaks every tool (monitoring, retries, caches) that relies on status codes. Use the right code.
Check yourself
4 questionsWhat do the five families (1xx–5xx) mean?
Show answerHide answer
Informational, success, redirection, client error, server error.
401 vs 403?
Show answerHide answer
401: not authenticated (who are you?). 403: authenticated but not permitted.
A user sees 504 from your load balancer. Where would you look first?
Show answerHide answer
At the app behind it — it's responding too slowly (slow queries, overloaded, stuck calls).
Which code for: a successful POST creating a note; a validation error in FastAPI; being rate limited?
Show answerHide answer
201; 422; 429.