0
0
Rest APIprogramming~20 mins

400 Bad Request in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
400 Bad Request Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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?
A200 OK
B500 Internal Server Error
C404 Not Found
D400 Bad Request
Attempts:
2 left
💡 Hint
Think about which status code means the client sent something wrong.
🧠 Conceptual
intermediate
2: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?
AThe client sent invalid or malformed data
BThe server encountered an unexpected error
CThe requested resource does not exist
DThe client is not authorized to access the resource
Attempts:
2 left
💡 Hint
400 means the client made a mistake in the request format or content.
Predict Output
advanced
2: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"}
A500 Internal Server Error
B400 Bad Request with error message about missing 'username'
C404 Not Found
D201 Created with user details
Attempts:
2 left
💡 Hint
Missing required fields usually cause client errors.
🔧 Debug
advanced
2: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"}
APassword should be a string, not a number
BMissing Authorization header
CIncorrect HTTP method used
DServer is down
Attempts:
2 left
💡 Hint
Check the data types expected by the API.
🚀 Application
expert
2: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?
AIgnore the error and continue
BRetry the request immediately without changes
CLog the error and prompt the user to correct the input data
DRestart the client application
Attempts:
2 left
💡 Hint
400 means the client sent bad data, so fix the data before retrying.