Challenge - 5 Problems
400 Bad Request Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the HTTP status code returned?
A client sends a malformed JSON payload to a REST API endpoint expecting JSON data. The server detects the invalid JSON format. What HTTP status code will the server most likely return?
Attempts:
2 left
💡 Hint
Think about which status code means the client sent something wrong.
✗ Incorrect
The 400 Bad Request status code means the server cannot process the request due to client error, such as malformed JSON.
🧠 Conceptual
intermediate2:00remaining
Cause of 400 Bad Request in REST APIs
Which of the following is the most common cause for a REST API to respond with a 400 Bad Request status?
Attempts:
2 left
💡 Hint
400 means the client made a mistake in the request format or content.
✗ Incorrect
400 Bad Request indicates the client sent invalid data or the request could not be understood by the server.
❓ Predict Output
advanced2:00remaining
Output of server response with missing required field
A REST API expects a JSON body with a required field 'username'. The client sends a JSON without 'username'. The server validates and returns a response. What is the likely HTTP status code and message?
Rest API
POST /api/users HTTP/1.1 Content-Type: application/json {"email": "user@example.com"}
Attempts:
2 left
💡 Hint
Missing required fields usually cause client errors.
✗ Incorrect
The server returns 400 Bad Request because the client did not provide a required field, making the request invalid.
🔧 Debug
advanced2:00remaining
Identify the cause of 400 Bad Request in this API call
A client sends this HTTP request to a REST API but receives a 400 Bad Request response. What is the most likely cause?
Rest API
POST /api/login HTTP/1.1 Content-Type: application/json {"username": "user1", "password": "12345"}
Attempts:
2 left
💡 Hint
Check the data types expected by the API.
✗ Incorrect
The API expects the password as a string, but the client sent a number, causing a validation error and 400 Bad Request.
🚀 Application
expert2:00remaining
How to handle 400 Bad Request in client code
You are writing client code to call a REST API. If the server responds with 400 Bad Request, what is the best way to handle it?
Attempts:
2 left
💡 Hint
400 means the client sent bad data, so fix the data before retrying.
✗ Incorrect
When receiving 400 Bad Request, the client should inform the user to fix the input data before retrying.