Bird
0
0

What is the likely cause of this 400 Bad Request error in a REST API?

medium📝 Debug Q7 of 15
Rest API - HTTP Status Codes

What is the likely cause of this 400 Bad Request error in a REST API?

PUT /api/profile HTTP/1.1
Content-Type: application/json

{"email": "user@example.com", "age": -5}
AMissing Content-Type header
BNegative age value is invalid
CIncorrect HTTP method for update
DEmail format is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check the JSON data

    The age field has a negative value (-5), which is usually invalid.
  2. Step 2: Understand validation rules

    API likely rejects negative age as invalid input, causing 400 Bad Request.
  3. Final Answer:

    Negative age value is invalid -> Option B
  4. Quick Check:

    Invalid field values cause 400 Bad Request [OK]
Quick Trick: Invalid field values trigger 400 Bad Request [OK]
Common Mistakes:
  • Ignoring negative values as invalid
  • Assuming missing headers cause 400
  • Confusing HTTP method with error cause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes