428

Precondition Required

Overview

428 Precondition Required means the server requires this request to be conditional. If a client sends a write without a precondition header like If-Match, the server refuses it and demands one.

The goal is to prevent the lost-update problem: if two clients each fetch the same resource and then save in turn, the later save silently overwrites the earlier one. By requiring If-Match, the server blocks such unconditional overwrites.

When it happens

Request / Response example

Request
PUT /docs/42 HTTP/1.1
Host: api.example.com
Content-Type: application/json

{"title":"New"}
Response
HTTP/1.1 428 Precondition Required
Content-Type: application/json

{"error":"precondition_required","hint":"Include an If-Match header with the current ETag."}

In code

app.put('/docs/:id', (req, res) => {
  if (!req.headers['if-match']) {
    return res.status(428).json({
      error: 'precondition_required',
      hint: 'Include an If-Match header with the current ETag.'
    });
  }
  // proceed with the conditional update...
});

Common causes

How to fix

Notes

Related status codes

Related headers

Specification