Backend and APIs · Question 21 of 50
Which HTTP status codes should every backend developer know?
API hygiene: clients and retries depend on these.
The answer
200 OK, 201 Created, 204 No Content. 301 and 308 are permanent redirects, 302 and 307 temporary (307 and 308 keep the method). 304 Not Modified: the cached copy is still good.
400 Bad Request, 401 not authenticated, 403 not allowed, 404 Not Found, 409 Conflict (a duplicate, or a version clash), 422 (well-formed but invalid, common in APIs), 429 Too Many Requests. 500 is a bug on our side, 502 Bad Gateway (the upstream answered badly), 503 Unavailable (overloaded or down, try later), 504 Gateway Timeout (the upstream took too long). 4xx: the client must fix the request. 5xx: a retry later may work.
The picture
2xx it worked 200 201 204 3xx look elsewhere 301 302 304 307 308 4xx you sent it wrong 400 401 403 404 409 422 429 5xx we broke 500 502 503 504
Should a validation error be 400 or 422?
Show the answer
Either can be defended. Be consistent, and put the field-level details in the body.