COMPUTER ENGINEER

Jump to examples
Blog
HTTP / HTTPS / TLS6 min study
55/ 70

Caching and conditional requests

Prevent lost updates with If-Match

Do not silently overwrite concurrent edits.

UnderstandStudy an examplePractise

Understand the concept

A client reads a resource with ETag v7 and submits If-Match: "v7" when editing. The server applies an atomic check-and-write or returns 412 when the representation changed. Checking a field and leaving a race before the write is insufficient.

If-Match uses strong comparison. A 428 can require a missing precondition; 409 is a broader state conflict. Clear status contracts improve handling.

The client can fetch current content and offer a diff or merge. Blindly retrying the old body against a new version can still overwrite someone else’s work. Concurrency checks do not replace resource authorisation.

WHEN TO USE IT

Protect edits across concurrent admin tabs.

COMMON PITFALL

Automatically overwriting with the old body after a 412.

01 / PRACTICE

One topic. Three levels of depth.

HTTP / illustrative example
ETag: "v7"

Version of the retrieved representation.

This page does not send requests to external servers. Messages are readable HTTP/1.1 illustrations, not HTTP/2 or HTTP/3 wire dumps. example.test is reserved for examples. Run commands and JavaScript only in your own test environment; never publish real tokens or cookies.

02 / YOUR TURN

Try it yourself first.

Is a check detached from the write sufficient?

Show the solution and explanation
Worked solution
Atomic condition + write

No; another update can occur between them.