🔑
428
Precondition Required
!
?

Example HTTP Response

HTTP Response
HTTP/1.1 428 Precondition Required
Common Causes
  • Missing If-Match or If-Unmodified-Since header
  • Optimistic locking required
  • Concurrent modification protection
Technical Details

What does this mean?

Say the magic words! The server needs conditional headers like If-Match to prevent you from overwriting someone else's changes.

Technical Definition

The origin server requires the request to be conditional to prevent lost updates.

RFC Says

"The 428 (Precondition Required) status code indicates that the origin server requires the request to be conditional. Its typical use is to avoid the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict."

Plain English:

428 means 'You need to include conditional headers (like If-Match) with this request.' It's used to enforce optimistic locking - requiring clients to prove they have the current version before making changes. This prevents the 'lost update' problem where two clients overwrite each other's changes.

Common Misinterpretation

Use 428 before the client sends the update (to tell them they need preconditions), not after. Once they send an update with preconditions that fail, use 412. Think of 428 as 'you must include If-Match' and 412 as 'your If-Match value was wrong'.

Code Snippets

Ready-to-use code for returning this HTTP status in your application:

Node.js
// Express.js
app.get('/example', (req, res) => {
  res.status(428).json({
    error: 'Precondition Required',
    message: 'Your error message here'
  });
});

// Native HTTP
const http = require('http');

http.createServer((req, res) => {
  res.writeHead(428, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({
    error: 'Precondition Required',
    message: 'Your error message here'
  }));
}).listen(3000);