Bad Request
The server cannot or will not process the request due to something that is perceived to be a client error.
What it means
The HTTP 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
How it works
- 1The client sends a request to the server.
- 2The server parses the request and detects a syntax error, missing required parameters, or invalid data.
- 3The server rejects the request immediately, returning a 400.
Why you're seeing this
- • Malformed syntax.
- • Invalid parameters or missing required fields.
- • Size limits exceeded on headers.
How to fix it
- • Check the API documentation to ensure you are sending exactly the payload and headers expected.
Framework Implementations
Express.js
app.post('/user', (req, res) => {
if (!req.body.email) {
return res.status(400).json({ error: 'Email is required' });
}
});Real-Life Scenarios
Use this whenever the client sends data that fails your validation logic (e.g., missing a required email field, or providing a string where an integer is expected).
Invalid JSON Body
A client sends a POST request with a malformed JSON payload (missing a closing bracket). The server's JSON parser throws an error, resulting in a 400.
HTTP Transaction
1. Client Request
POST /api/users HTTP/1.1
Content-Type: application/json
{"name": "John", "email": }2. Server Response
HTTP/1.1 400 Bad Request
Content-Type: application/json
{"error": "Invalid JSON payload"}SEO Implications
Search engines will not index a page returning a 400. Ensure valid links don't lead to 400 errors.