428 Precondition Required HTTP Status Code
Description
HTTP status code 428 indicates "Precondition Required." It is a response status code that specifies that the server requires the request to be conditional. Typically, it means that the request must include certain conditions, like using appropriate headers, to proceed. This can be used to ensure that requests are made with the necessary context or prerequisites, preventing issues such as state-changing requests being made without awareness of the current state. Essentially, it's a way for the server to enforce certain preconditions that must be met by the client before the requested method is allowed to be executed, helping to maintain the integrity and reliability of the server's responses.
Status
428 Precondition Required
Common Causes
Here are some common causes and scenarios where a 428 status code might be used:
Concurrency Control: When multiple clients are accessing and possibly modifying a resource concurrently, the server might require each client to include a precondition (like an
If-Match
header with an entity tag) to ensure that each client is working with the latest version of the resource. This helps prevent the "lost update" problem, where changes made by one client are accidentally overwritten by another.Stateful Operations: For operations that depend on the resource being in a certain state, the server might require a precondition to ensure that the state has not changed unexpectedly before applying the operation. This is particularly useful in RESTful APIs where operations are supposed to be stateless, and the server needs to ensure state consistency.
Resource Integrity: To ensure that a resource has not been altered in an unexpected way between the time it was last accessed by the client and the time a modification request is made, the server might demand a precondition check. This can help maintain data integrity, especially in critical applications.
Avoiding Repeated Actions: In some cases, the server wants to ensure that a particular action is not repeated accidentally (e.g., due to a retry mechanism in the client). By requiring a precondition, the server can make sure that the client is deliberately performing the action with the current state of the resource in mind.
Conditional Requests: More generally, any scenario where the server needs to ensure that the client is making a request based on up-to-date information might lead to the use of a 428 status. This is part of a broader strategy to make HTTP interactions more reliable and consistent, avoiding issues like stale reads or unintentional overwrites.
In practice, receiving a 428 response typically means that the client needs to adjust its request to include the appropriate conditional headers (like If-Match
, If-None-Match
, If-Modified-Since
, etc.) based on the current state of the resource as understood by the client. This can involve fetching the current state of the resource to obtain the necessary tokens (e.g., ETags) or timestamps.
Browser Support
The following table will show you the current browser support for the 428 Precondition Required
HTTP status code.
Desktop | |||||
? | ? | ? | ? | ? |
Tablets / Mobile | |||||
? | ? | ? | ? | ? | ? |
Last updated by CSSPortal on: 1st April 2024