Designing HTTP APIs · core
Status codes that mean what they say
Status codes tell clients and infrastructure what happened: 2xx success, 3xx redirect or cache, 4xx the client must change the request, 5xx the server failed, so returning 200 with an error inside breaks retries, caches and monitoring.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- 2xx: 200 OK, 201 Created (+ Location), 202 Accepted (work queued), 204 No Content (success with no body).
- 3xx: 301/308 permanent and 302/307 temporary redirects (307/308 keep the method), 304 Not Modified (conditional GET with ETag).
- 4xx: 400 bad input, 401 not authenticated, 403 authenticated but not allowed, 404 not found, 405 method not allowed, 409 conflict (duplicate, version clash), 412 precondition failed (If-Match), 413 body too large, 415 wrong content type, 422 well-formed but invalid, 429 too many requests (+ Retry-After).
- 5xx: 500 bug, 502 bad gateway (an upstream gave a bad reply), 503 unavailable (overloaded or deploying; may send Retry-After), 504 gateway timeout (upstream too slow).
- Clients and tools rely on these: retry 5xx/429 with backoff, never blindly retry 4xx; dashboards alert on 5xx rate.
- An empty list is 200 with [], not 404. A missing single resource is 404.
The red pen
Common traps: mistake → fix
Mistake: Return 200 with { success: false }
Fix: caches, retries and monitoring all think it worked.
Mistake: 401 when the user lacks permission
Fix: that is 403; 401 means 'who are you?'.
Mistake: 500 for validation errors
Fix: 5xx says the server is broken; bad input is 400 or 422.
Easy to hard
Questions interviewers ask, easy to hard
- Which status codes do you use most and when?
- 401 vs 403? 400 vs 422? 502 vs 503 vs 504?
- When do you return 202 or 204?
- How should a frontend react to 401, 403, 409, 429 and 503?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.