Example HTTP Response
HTTP/1.1 400 Bad Request
Content-Type: application/json
{"error": "Invalid request format"}- Malformed JSON in request body
- Missing required fields
- Invalid query parameters
What does this mean?
Huh? The server is scratching its head because your request doesn't make sense. Like ordering a pizza with negative toppings.
Technical Definition
The server cannot process the request due to client error (malformed syntax, invalid request framing, etc.).
RFC Says
"The 400 (Bad Request) 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)."
Plain English:
The request is malformed or invalid - there's something wrong with how you structured the request itself. Use this for syntax errors like invalid JSON, malformed headers, or completely missing required data.
Common Misinterpretation
400 is for syntax/formatting errors, not validation errors. If the request is syntactically valid but the data fails business logic validation (e.g., invalid email format, date in the past), use 422 (Unprocessable Entity) instead. 400 means 'I can't even parse your request,' while 422 means 'I understand your request but the data doesn't make sense.'
Ready-to-use code for returning this HTTP status in your application:
// Express.js
app.get('/example', (req, res) => {
res.status(400).json({
error: 'Bad Request',
message: 'Your error message here'
});
});
// Native HTTP
const http = require('http');
http.createServer((req, res) => {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: 'Bad Request',
message: 'Your error message here'
}));
}).listen(3000);- Request is syntactically malformed (invalid JSON, wrong content-type)
- Required parameters are missing entirely
- Use 422 instead when syntax is valid but semantically incorrect
- Generic client error when no more specific 4xx code applies