API Design FundamentalsLesson 1.3
HTTP status codes every backend developer must know
2xx success codes, 4xx client errors, 5xx server errors, 201 vs 200, 400 vs 422, 401 vs 403, idempotency signals
HTTP status codes every backend developer must know
Status Codes Are Contracts
Returning 200 OK with an error message in the body is a lie. Status codes communicate machine-readable semantics. Clients, proxies, and monitoring tools all read them. Get them right.
The Codes You Will Use Daily
2xx Success
200— generic success, used with GET and PUT201— resource created, includeLocationheader pointing to the new resource204— success with no body, common for DELETE
4xx Client errors
400— malformed request syntax401— unauthenticated, no or invalid token403— authenticated but not authorized404— resource not found409— conflict, e.g. duplicate email422— valid syntax but semantic validation failed429— rate limit exceeded
5xx Server errors
500— unhandled server error503— service unavailable, overload or maintenance
Common Mistakes
Using 400 for everything is lazy. Distinguish between a missing field (400), a field that fails business logic (422), and a duplicate resource (409). Clients need this precision to handle errors programmatically without parsing your error messages.
