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 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
- B.422 is identical to 400 Bad Request; the choice between them is arbitrary
- C.422 should be used for authentication failures; 400 should be used for authorization failures
- D.422 is a server-side error code; 400 is the correct client-side validation error code for all cases
Why A is correct