HTTP Conditional Requests and ETags: Revalidate Caches and Prevent Edit Conflicts
HTTP conditional requests let a client tell the server which representation it last saw and make an operation depend on whether that state is still current. For reads, ETag with If-None-Match can validate a cached representation and avoid resending its body with 304. For updates, If-Match can prevent a stale edit from overwriting another user's change. The server must support and evaluate the condition correctly.
HTTP conditional requests let a client tell the server which representation it last saw and make an operation depend on whether that state is still current. For reads, ETag with If-None-Match can validate a cached representation and avoid resending its body with 304. For updates, If-Match can prevent a stale edit from overwriting another user's change. The server must support and evaluate the condition correctly.
An ETag is an opaque validator for a selected representation, not a resource ID or permission token. Strong tags change when representation bytes change; weak tags marked W/ can mean semantically equivalent even when bytes differ. RFC 9110 uses strong comparison for If-Match and weak comparison for If-None-Match.
Revalidate a cached GET
Store the response body and ETag. Later send GET /docs/7 with If-None-Match: "rev-42". If the selected representation still matches, the server can return 304 Not Modified with no body; reuse the stored body. If it differs, the server returns the current representation, usually 200, and a new ETag. If-None-Match is primarily for GET/HEAD revalidation. If-Modified-Since is a date-based alternative, but RFC 9110 says to ignore it when If-None-Match is present. Cache-Control, Vary, and other caching rules still apply.
Prevent lost updates
Two users read a document with ETag "rev-42". After the first saves, the current tag becomes "rev-43". The second user can condition their update on the version they saw:
PUT /docs/7
If-Match: "rev-42"
Content-Type: application/json
{ "title": "Draft title", "body": "Edited content" }The server evaluates the condition before applying the change. If the tag still matches, it stores the update and returns a new ETag. If not, it does not apply the request and returns 412 Precondition Failed. The client should fetch the latest representation and resolve the conflict; blindly resending the old body can recreate the overwrite. If-Match uses strong comparison. If-Match: * instead checks that a current representation exists.
| Goal | Condition | If the condition does not match |
|---|---|---|
| Validate a cached read | GET + If-None-Match: | 304; use the cached body |
| Prevent a stale edit | Update method + If-Match: | Usually 412; change is not applied |
| Create only if absent | Supported update + If-None-Match: * | Condition fails if resource exists |
A server can also use If-None-Match: * to prevent creating over an existing representation. Check the API's actual method/condition contract; these protections are not automatic when the server does not implement them.
Before using validators
Document which representation a tag identifies, including language or encoding variants. For lost-update protection, use a strong validator and make compare-and-write atomic so a concurrent change cannot slip between the check and save. Ensure a 304 response lets the cache reuse the stored body and correct metadata. On 412, fetch and reconcile instead of simply changing the tag and retrying. Conditional requests do not serialize edits or merge them automatically.
References
[RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html)
[RFC 9111: HTTP Caching](https://www.rfc-editor.org/rfc/rfc9111.html)