An ETag is an opaque HTTP validator identifying a particular version of a resource representation. Because content negotiation can produce different JSON and XML representations, each may have a different ETag. section 12.5.4 section 13.4.4
Use the ETag with conditional requests to protect updates and reduce response data:
- Return ETag: z567dff when reading a resource. section 12.5.4
- Send If-Match: z567dff on an update; return 412 Precondition Failed when the representation changed. section 12.5.4
- Send If-None-Match: z567dff when validating cached data; return 304 Not Modified if unchanged, or 200 OK with new data and ETag if modified. section 13.4.5
Preventing a stale account update
A consumer reads an account and receives ETag: z567dff. Before updating, it sends If-Match: z567dff. If another change occurred, the API rejects the request with 412, prompting the consumer to reread the account. section 12.5.4
Figure 12.5 By returning the resource data version in an Etag header on reading, we can condition updates with the If-Match header and ensure that data stays uncorrupted.
Trace how a returned ETag conditions a later update through If-Match. section 12.5.4
