HTTP 422 Unprocessable Content indicates that the server understands the request format and syntax, but cannot process it due to semantic or validation errors in the request data.
? Key Concepts
Request syntax is correct (unlike 400)
Validation or business-rule failure
Common in REST APIs and form submissions
Frequently returned with detailed error messages
? Syntax / Theory
422 is part of the WebDAV extension and is widely adopted in modern APIs. It is typically used when submitted JSON or form data fails server-side validation.
? Code Example(s)
? View Code Example
// Express.js example returning HTTP 422 for invalid input
const app = require('express')();
app.post("/users",(req,res)=>{
if(!req.body.email){
return res.status(422).json({error:"Email is required"});
}
res.status(201).json({message:"User created"});
});
? Live Output / Explanation
Server Response
If the email field is missing, the server responds with status 422 and a clear validation message instead of processing the request.
? Interactive Example / Diagram
Live API Simulator
Try submitting the form without an email to trigger a 422 error.
?? Use Cases
Form validation failures
API payload rule violations
Invalid state transitions
Missing required business fields
✅ Tips & Best Practices
Return clear validation messages with 422
Use 422 instead of generic 400 for semantic errors