HTTP

HTTP 400 Bad Request vs 428 Precondition Required

Both HTTP 400 (Bad Request) and 428 (Precondition Required) belong to the 4xx Client Error category. 400 indicates that the server cannot process the request due to malformed syntax, invalid request message framing, or deceptive request routing. Meanwhile, 428 means that the server requires the request to be conditional (e.g., include If-Match header) to prevent lost updates.

Description

The server cannot process the request due to malformed syntax, invalid request message framing, or deceptive request routing.

When You See It

When sending malformed JSON, missing required fields, or invalid query parameters.

How to Fix

Check the request body format, validate all required fields, and ensure proper encoding.

Description

The server requires the request to be conditional (e.g., include If-Match header) to prevent lost updates.

When You See It

When an API requires optimistic concurrency control via ETags.

How to Fix

Fetch the resource first to get its ETag, then include If-Match in your update request.

Key Differences

1.

HTTP 400: The server cannot process the request due to malformed syntax, invalid request message framing, or deceptive request routing.

2.

HTTP 428: The server requires the request to be conditional (e.g., include If-Match header) to prevent lost updates.

3.

You encounter 400 when when sending malformed JSON, missing required fields, or invalid query parameters.

4.

You encounter 428 when when an API requires optimistic concurrency control via ETags.

When to Use Which

For 400 (Bad Request): Check the request body format, validate all required fields, and ensure proper encoding. For 428 (Precondition Required): Fetch the resource first to get its ETag, then include If-Match in your update request.

Learn More