Bird
0
0

You are designing a REST API endpoint for user registration. Which approach best uses the 422 status code to improve client communication when input data is invalid?

hard📝 Application Q15 of 15
Rest API - HTTP Status Codes
You are designing a REST API endpoint for user registration. Which approach best uses the 422 status code to improve client communication when input data is invalid?
AReturn 422 with a JSON object listing each invalid field and a clear error message.
BReturn 422 with a generic message: 'Invalid data'.
CReturn 400 Bad Request without details about the errors.
DReturn 200 OK and ignore invalid fields silently.
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of 422

    422 is used to tell clients exactly what data is invalid to help fix input.
  2. Step 2: Choose detailed error reporting

    Providing a JSON object with each invalid field and message improves client experience.
  3. Final Answer:

    Return 422 with a JSON object listing each invalid field and a clear error message. -> Option A
  4. Quick Check:

    422 + detailed errors = better client feedback [OK]
Quick Trick: Use 422 with detailed errors for clear client feedback [OK]
Common Mistakes:
  • Sending vague error messages
  • Using wrong status codes like 400 or 200
  • Not informing client about specific invalid fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes