What is the HTTP '422 Unprocessable Entity' status code and when should it be used in REST APIs instead of 400?
- A.400 Bad Request indicates the client lacks permission for the resource (an authorization failure, like an expired token). 422 Unprocessable Entity indicates the server understood the credentials and the resource is locked by another user (a conflict on the same record), so clients should always retry after a delay. 422 tells clients the request collided with a concurrent update, which makes it the right code instead of 409 for every optimistic locking failure in a REST API
- B.400 Bad Request indicates the server cannot parse the request (malformed JSON, invalid syntax). 422 Unprocessable Entity indicates the request is syntactically valid and parseable but semantically invalid (e.g., valid JSON with a start_date after end_date, valid email format but domain doesn't exist, valid number but outside business range). 422 tells clients the structure was understood but the content violated business rules
- C.