Bird
0
0

When should a REST API return a 422 Unprocessable Entity status code?

easy📝 Conceptual Q2 of 15
Rest API - HTTP Status Codes
When should a REST API return a 422 Unprocessable Entity status code?
AWhen the user is not authenticated
BWhen the requested URL does not exist
CWhen the request body is syntactically correct but contains invalid data
DWhen the server is down for maintenance
Step-by-Step Solution
Solution:
  1. Step 1: Identify the condition for 422

    422 is used when the request syntax is correct but the data is invalid or semantically wrong, like missing required fields or invalid formats.
  2. Step 2: Eliminate other options

    404 is for missing URLs, 401 for authentication, and 503 for server maintenance, so they don't fit 422.
  3. Final Answer:

    When the request body is syntactically correct but contains invalid data -> Option C
  4. Quick Check:

    422 triggers on invalid data, not missing URL or auth [OK]
Quick Trick: Use 422 for valid syntax but invalid data [OK]
Common Mistakes:
  • Returning 404 instead of 422 for bad data
  • Using 401 for data validation errors
  • Confusing 422 with server errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes