Bird
0
0

What will happen if a REST API receives this HTTP request with a malformed JSON payload?

medium📝 Predict Output Q5 of 15
Rest API - HTTP Status Codes

What will happen if a REST API receives this HTTP request with a malformed JSON payload?

POST /api/register HTTP/1.1
Content-Type: application/json

{"email": "user@example.com", "password": "pass123"
AThe server responds with a 400 Bad Request status indicating invalid JSON
BThe server processes the request successfully and returns 200 OK
CThe server returns a 404 Not Found error
DThe server returns a 500 Internal Server Error due to parsing failure
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the JSON payload

    The JSON is malformed because it is missing a closing brace.
  2. Step 2: Understand server behavior

    Most REST APIs validate JSON and respond with 400 Bad Request if invalid.
  3. Final Answer:

    The server responds with a 400 Bad Request status indicating invalid JSON -> Option A
  4. Quick Check:

    Malformed JSON triggers 400 Bad Request [OK]
Quick Trick: Malformed JSON causes 400 Bad Request response [OK]
Common Mistakes:
  • Assuming server returns 500 Internal Server Error
  • Thinking server ignores JSON errors and returns 200
  • Confusing 400 with 404 Not Found

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes