Example HTTP Response
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
{"errors": {"email": "Invalid email format"}}- Validation errors in request body
- Semantically incorrect data
- Business logic validation failed
What does this mean?
I understand what you're saying, but it doesn't make sense! Like asking to schedule a meeting for February 30th.
Technical Definition
The request was well-formed but was unable to be followed due to semantic errors.
RFC Says
"The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415 Unsupported Media Type status code is inappropriate), and the syntax of the request entity is correct (thus a 400 Bad Request status code is inappropriate) but was unable to process the contained instructions."
Plain English:
422 means 'I understood your request and it's syntactically correct, but it has semantic or validation errors.' For example, a properly formatted JSON request where the email field contains 'not-an-email' or a date field has an impossible value like February 30th.
Common Misinterpretation
The line between 400 and 422 is blurry. Generally, use 400 for syntax errors (malformed JSON, missing required fields) and 422 for semantic validation errors (invalid email format, business rule violations). However, many APIs just use 400 for all client errors.
Ready-to-use code for returning this HTTP status in your application:
// Express.js
app.get('/example', (req, res) => {
res.status(422).json({
error: 'Unprocessable Entity',
message: 'Your error message here'
});
});
// Native HTTP
const http = require('http');
http.createServer((req, res) => {
res.writeHead(422, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: 'Unprocessable Entity',
message: 'Your error message here'
}));
}).listen(3000);- Request is syntactically valid but fails semantic validation
- Form field validation errors (invalid email, password too weak)
- Business logic violations (date in past, negative quantity)
- Use 400 for malformed requests that can't be parsed at all