Bird
Raised Fist0

You want to design a REST API that returns error codes machines can easily understand and act on. Which approach is best?Choose the best practice:

hard🚀 Application Q15 of Q15
Rest API - Error Handling

You want to design a REST API that returns error codes machines can easily understand and act on. Which approach is best?

Choose the best practice:

AReturn random status codes to confuse attackers
BReturn only HTTP status codes without any message body
CReturn success status codes even when errors happen, but include error details in HTML
DReturn HTTP status codes with clear JSON error messages explaining the problem
Step-by-Step Solution
Solution:
  1. Step 1: Understand best practices for machine-readable errors

    Machines need both status codes and clear JSON messages to understand errors and automate responses.
  2. Step 2: Evaluate options

    Return HTTP status codes with clear JSON error messages explaining the problem provides both HTTP status codes and JSON messages, which is the recommended approach.
  3. Final Answer:

    Return HTTP status codes with clear JSON error messages explaining the problem -> Option D
  4. Quick Check:

    Status + JSON error message = best practice [OK]
Quick Trick: Use status codes plus JSON messages for clear machine errors [OK]
Common Mistakes:
MISTAKES
  • Sending no message body with status codes
  • Using success codes for errors
  • Returning HTML instead of JSON for errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes