Precondition Required
Production Risk
Low. It's a best practice for robust APIs, forcing clients to avoid accidental data overwrites. A client developer will see the error and know to implement conditional requests.
The origin server requires the request to be conditional. This response is intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, while another client has modified the state on the server in the meantime.
- 1A client attempts to PUT or PATCH a resource without providing a conditional header like 'If-Match'.
- 2The server is configured to require optimistic concurrency control on all state-changing requests.
- 3This forces clients to be explicit about which version of a resource they are attempting to modify.
A user tries to update a resource via an API without providing the 'If-Match' header containing the resource's current ETag.
PUT /api/items/123 HTTP/1.1 Host: example.com
expected output
HTTP/1.1 428 Precondition Required
Fix
Add a Conditional Header
WHEN Making a state-changing request to a server that requires it.
// First, GET the resource to find its ETag // Then, include the ETag in the PUT request PUT /api/items/123 HTTP/1.1 If-Match: "the-current-etag"
Why this works
Client-Side Logic
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev