Skip to content
ADP
API Design PrincipleBETA

ETag

An ETag (Entity Tag) is an HTTP response header used for web cache validation. It is a unique identifier assigned by a web server to a specific version of a resource. ETags help improve efficiency by allowing browsers to make conditional requests, reducing unnecessary data transfer.

Key Points

  1. Purpose: ETags enable caching systems to determine if the content of a resource has changed.

  2. Format: An ETag is typically a string enclosed in double quotes, e.g., ETag: "686897696a7c876b7e".

  3. Types:

    • Strong ETags: Change if there's any difference in the response body.
    • Weak ETags: Change only if there are significant semantic changes.
  4. Usage:

    • Server sends ETag with response.
    • Client includes ETag in subsequent requests using If-None-Match header.
    • Server compares ETags to determine if resource has changed.
  5. Benefits:

    • Reduces bandwidth usage.
    • Improves server performance.
    • Ensures data consistency.
  6. Considerations:

    • Generation method can impact performance.
    • Should be used in conjunction with other caching mechanisms.

Guidance

  • SHOULD use ETags for all cacheable resources.
  • MUST generate unique ETags for each version of a resource.
  • SHOULD use strong ETags unless performance considerations necessitate weak ETags.
  • MUST include the ETag in the response headers for GET and HEAD requests.
  • SHOULD support conditional requests using If-Match and If-None-Match headers.
  • MUST return a 304 Not Modified response if the ETag matches in a conditional GET request.
  • SHOULD use consistent ETag generation methods across distributed systems.

Example

http
HTTP/1.1 200 OK
Content-Type: text/html
ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"

[Resource content]

Use the Shared Headers defined in ADP-767

yaml
headers:
   ETag:
      - "$ref": "https://vivotek-it.github.io/api-design-principles/definitions.yaml#/parameters/Etag"

References