Skip to content

Entity tag

An ETag identifies a particular representation version of an HTTP resource and supports conditional reads or changes.

Also known asETag
APIs and data contracts

An entity tag is an HTTP validator in the ETag response header. It identifies a particular version of the representation served. The value need not be a content hash and should be treated by the client as an opaque identifier, not a sortable version number.

Two conditional requests

A fictional project overview responds with ETag: "r7". On a later GET with If-None-Match: "r7", the server can return 304 without resending the body if the representation is unchanged. If it changed, the new representation is transferred with its new validator.

For a change, the same identifier has another role: an edit using If-Match: "r7" encounters the now-current representation "r8". The unmet precondition produces 412 instead of overwriting the newer state with the old edit. The application must handle this conflict visibly. Checking and changing must work together correctly on the server; sending a header alone provides no protection.

If-Match uses strong comparison. A weak validator with the W/ prefix does not satisfy this comparison. Cache reads and write checks therefore use different conditions. An ETag does not replace an authorisation check and does not decide who may see or change the data.

Sources