The HTTP 400 status code stands for "Bad Request". It is a client error response, indicating that the server cannot process the request due to malformed syntax, invalid data, or missing required parameters.

When is HTTP 400 Used?

  • When a request has incorrect syntax or is not properly formatted.
  • When required parameters are missing or invalid.
  • When invalid JSON, XML, or query parameters are sent to an API.
  • When a request exceeds size limits or contains unsupported characters.

Example Scenarios

  • Invalid JSON Format – Sending a request with broken JSON syntax.
  • Missing Required Fields – Submitting a form without required input fields.
  • Exceeding URL Length Limits – Sending a request with an excessively long URL.

Example

Client Request (Malformed JSON in API Request)

    
        POST /api/user HTTP/1.1
        Host: example.com
        Content-Type: application/json

        { "username": "john", "email": "john@example.com", }  <-- Extra comma (invalid JSON)
    

Server Response (400 Bad Request Due to Invalid JSON)

    
        HTTP/1.1 400 Bad Request
        Content-Type: application/json

        { "error": "Invalid JSON format" }
    

Summary

HTTP 400 means the server cannot process the request due to bad syntax, invalid parameters, or incorrect formatting. It is commonly seen in API requests, form submissions, and invalid client-side requests.