4xx Client Errors

HTTP 400 Bad Request

The server cannot or will not process the request due to a client error.

When is 400 used?

  • Malformed JSON or XML body
  • Invalid query parameters
  • Request body too large

How to handle a 400 response

Inspect the request — URL, method, headers, credentials, and body. Retrying the same request unchanged will usually fail again; 429 is the exception, where you should wait for the Retry-After period.

Check the status code a URL returns from the command line:

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

How to return 400 from your server

Node.js (Express)

res.status(400).json({ message: 'Bad Request' });

Python (Flask)

return {"message": "Bad Request"}, 400

Go (net/http)

w.WriteHeader(400)

Frequently Asked Questions

What does HTTP 400 mean?

400 Bad Request: The server cannot or will not process the request due to a client error.

Is 400 an error?

Yes. 400 is in the 4xx Client Errors class. Client errors: the request is malformed, unauthorized, or targets something that does not exist.