0
0
Rest APIprogramming~10 mins

422 Unprocessable Entity in Rest API - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - 422 Unprocessable Entity
Client sends HTTP request
Server receives request
Server validates request data
Data valid
Process request
Return success
The server checks the request data. If data is invalid but syntax is correct, it returns 422 Unprocessable Entity error.
Execution Sample
Rest API
POST /users HTTP/1.1
Content-Type: application/json

{"email": "not-an-email"}
Client sends a POST request with invalid email format in JSON body.
Execution Table
StepActionRequest DataValidation ResultServer Response
1Receive request{"email": "not-an-email"}Not validated yetNone
2Validate email format{"email": "not-an-email"}Invalid email formatPrepare 422 response
3Send response{"email": "not-an-email"}Invalid email format422 Unprocessable Entity
💡 Validation failed due to invalid email format, so server returns 422 error.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
request_dataNone{"email": "not-an-email"}{"email": "not-an-email"}{"email": "not-an-email"}
validation_resultNoneNoneInvalid email formatInvalid email format
server_responseNoneNonePrepare 422 response422 Unprocessable Entity
Key Moments - 2 Insights
Why does the server return 422 instead of 400 Bad Request?
422 means the request syntax is correct but the data is invalid. 400 is for malformed syntax. See execution_table step 2 where validation fails but request is syntactically valid.
Can the server process the request if it returns 422?
No, the server cannot process invalid data. It stops and returns 422 as shown in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the validation result at step 2?
AValid data
BInvalid email format
CSyntax error
DNo validation done
💡 Hint
Check the 'Validation Result' column at step 2 in execution_table.
At which step does the server send the 422 response?
AStep 1
BStep 2
CStep 3
DNo 422 response sent
💡 Hint
Look at the 'Server Response' column in execution_table.
If the email was valid, how would the server_response variable change after step 3?
AIt would be a success response
BIt would be None
CIt would be 422 Unprocessable Entity
DIt would be a 400 Bad Request
💡 Hint
Refer to variable_tracker for server_response variable and think about valid data processing.
Concept Snapshot
422 Unprocessable Entity means the server understands the request syntax but the data is invalid.
Used when request body has correct format but fails validation.
Server responds with status 422 and error details.
Client should fix data and resend.
Different from 400 Bad Request which means syntax error.
Full Transcript
When a client sends a request to a server, the server first checks if the request is correctly formed. If the syntax is correct but the data inside is invalid, the server returns a 422 Unprocessable Entity error. For example, if an email field is not a valid email format, the server will reject it with 422. This means the client must fix the data before trying again. The server does not process invalid data. This is different from a 400 Bad Request, which means the request syntax itself is wrong. The 422 status helps clients understand that the request was understood but the content is wrong.