How do 400, 401, 403, 404, 409, 415, 422 and 429 differ in an API?
Answer
400 is a generic malformed/invalid request; 401 normally means authentication is missing or invalid; 403 means the caller is not permitted; 404 means the resource is not found; 409 is a conflict with current state; 415 means the request media type is unsupported; 422 means the server understands the syntax but cannot process the content semantically; and 429 means the client exceeded a rate limit. A strong API test checks that the exact failure maps to the intended contract code.
Strong answer includes
- 401 authentication versus 403 authorization
- 409 conflict versus 422 semantic validation
- 415 media type and 429 rate limiting
Practical example
A request with an expired token should normally fail as 401, while the same endpoint called with a valid token for a user lacking the admin role should fail as 403 rather than being treated as the same authentication case.