← Back to Chapters

HTTP 428 – Precondition Required

? HTTP 428 – Precondition Required

? Quick Overview

HTTP status code 428 Precondition Required indicates that the server requires the request to be conditional. This status is used to prevent lost updates by ensuring the client includes specific preconditions before modifying a resource.

? Key Concepts

  • Used mainly with REST APIs
  • Helps prevent accidental overwrites
  • Works with conditional headers like If-Match
  • Introduced in HTTP/1.1 extensions

? Syntax / Theory

A server responds with 428 when a client attempts to update a resource without providing required preconditions. Most commonly, servers expect an If-Match header containing an ETag.

? View Code Example
// Example HTTP request missing required precondition PUT /api/users/42 HTTP/1.1 Host: example.com Content-Type: application/json {"name":"New Name"}

? Live Output / Explanation

Server Response

The server rejects the request and responds with status code 428 Precondition Required, indicating that a conditional header is mandatory.

? Interactive Example

Simulate API Request

Toggle the header below to see how the server handles the request.

PUT /api/resource HTTP/1.1 Host: example.com Content-Type: application/json {"status": "update"}
? View Code Example
// Correct request including If-Match header PUT /api/users/42 HTTP/1.1 Host: example.com If-Match: "e0023aa4" Content-Type: application/json {"name":"New Name"}

? Use Cases

  • Updating user profiles safely
  • Preventing race conditions in APIs
  • Ensuring data consistency in distributed systems

✅ Tips & Best Practices

  • Always use ETags for mutable resources
  • Combine with If-Match for safe updates
  • Return clear error messages with 428 responses

? Try It Yourself

  1. Create a REST endpoint that requires If-Match
  2. Send a request without the header and observe 428
  3. Retry with a valid ETag and confirm success