Skip to content

428 Precondition Required (HTTP Status Code 428)

Updated: at 09:12 AM

HTTP status code 428 indicates that the server requires the client to meet certain preconditions in order to process the request. This status code was introduced in 2012 through RFC 6585.

Key Features and Use Cases

Implementation

The server typically requires the client to use conditional request headers, such as If-Match or If-Unmodified-Since.

Client Response

Upon receiving this status code, the client must include the necessary preconditions in the request and resend it.

Security

Using this status code can prevent accidental updates or overwrites, helping to maintain data consistency.

Specific Situations

This status code is particularly useful in:

Example Scenario

Consider an online document editing system where multiple users might edit the same document simultaneously. To prevent users from unintentionally overwriting each other’s changes, the server may require that each update request includes the current version number of the document. If the version number does not match, the server will return a 428 status code, prompting the client to first retrieve the latest version before making edits.

PUT /document/123 HTTP/1.1
Host: example.com
If-Match: "e0023aa4e"

{"title": "Updated Title", "content": "New content..."}

If the client does not include the If-Match header, or if the provided ETag does not match, the server may respond:

HTTP/1.1 428 Precondition Required
Content-Type: application/json

{
  "error": "Precondition Required",
  "message": "Please provide a valid If-Match header with the current ETag of the resource."
}

This mechanism helps to ensure the consistency and integrity of data, especially in distributed systems or high concurrency environments.