Bird
0
0

You find that your REST API returns some responses with a field "status_code" as a number and others as a string. What is the best fix?

medium📝 Debug Q7 of 15
Rest API - Request and Response Format
You find that your REST API returns some responses with a field "status_code" as a number and others as a string. What is the best fix?
ARemove the "status_code" field entirely
BReturn "status_code" as a string to avoid parsing errors
CLet clients handle both types without changes
DAlways return "status_code" as a number for consistency
Step-by-Step Solution
Solution:
  1. Step 1: Identify inconsistency in data type for "status_code"

    Mixing number and string types causes client parsing issues.
  2. Step 2: Choose consistent data type for better usability

    Returning "status_code" always as a number is standard and easier for clients to handle.
  3. Final Answer:

    Always return "status_code" as a number for consistency -> Option D
  4. Quick Check:

    Consistent data types avoid client errors [OK]
Quick Trick: Keep data types consistent for all fields [OK]
Common Mistakes:
MISTAKES
  • Returning mixed types causes parsing errors
  • Removing important fields breaks clients
  • Expecting clients to handle inconsistent types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes