Logo
DevUtilsAll-in-one toolkit
Back to all codes
4284xx
4xx — Client Error

Precondition Required

The origin server requires the request to be conditional.

What it means

The HTTP 428 Precondition Required response status code indicates that the server requires the request to be conditional.

Typically, this means that a required precondition header, such as `If-Match`, is missing. This status code allows a server to prevent the "lost update" problem by forcing the client to use conditional requests.

How it works

  • 1The client sends a PUT request to update a resource.
  • 2The server is strictly configured to prevent accidental overwrites.
  • 3The client didn't include an 'If-Match' header, so the server rejects the request with 428.
  • 4The client must fetch the ETag, and retry the request with 'If-Match'.

Why you're seeing this

  • Missing If-Match or If-Unmodified-Since headers.

How to fix it

  • Perform a GET request to obtain the current ETag, then include it in the `If-Match` header of your PUT request.

Framework Implementations

Express.js

app.put('/resource', (req, res) => {
  if (!req.headers['if-match']) {
    return res.status(428).send('Precondition Required');
  }
});

Real-Life Scenarios

Use this on critical API endpoints (like financial records or shared documents) to explicitly force all clients to implement Optimistic Concurrency Control.

Forced Safety

A developer writes a script to update product prices. They send a PUT request without checking the current version. The API returns 428 to force them to write safer code.

HTTP Transaction

1. Client Request

PUT /api/product/123 HTTP/1.1

{"price": 20}

2. Server Response

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

{"error": "You must provide an If-Match header to update this resource."}

SEO Implications

None.

Related Codes

Official Spec

RFC 6585, Section 3