Bird
Raised Fist0

You want to design a REST API error response that clearly tells the user their input is missing a required field called "email". Which JSON response is best?

hard🚀 Application Q8 of Q15
Rest API - Error Handling

You want to design a REST API error response that clearly tells the user their input is missing a required field called "email". Which JSON response is best?

A{"error": 400, "message": "email"}
B{"error": "Missing required field", "field": "email", "code": 400}
C{"message": "Error", "code": "email missing"}
D{"status": "error", "details": 400}
Step-by-Step Solution
Solution:
  1. Step 1: Identify clear error description and field name

    {"error": "Missing required field", "field": "email", "code": 400} clearly states the error and specifies which field is missing.
  2. Step 2: Check for proper data types and keys

    {"error": "Missing required field", "field": "email", "code": 400} uses strings for error and field, and numeric code for status.
  3. Final Answer:

    {"error": "Missing required field", "field": "email", "code": 400} -> Option B
  4. Quick Check:

    Clear error + field name + code = Best response [OK]
Quick Trick: Specify missing field in error message [OK]
Common Mistakes:
MISTAKES
  • Using numbers instead of strings for messages
  • Not specifying which field is missing
  • Mixing up keys and values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes