Skip to content
ADP
API Design PrincipleBETA

[ADP-369] HTTP Caching: ETag

Overview

The ETag header is used for resource versioning and cache validation. For detailed information about ETag, please refer to ADP-128: ETag.

Procedures

  1. The client initiates the first GET request without any cache-related headers.
  2. The server returns the data with a calculated ETag.
  3. The client requests the same GET again with If-None-Match.
  4. The server checks the If-None-Match request against the latest data's ETag.
    1. return 200 if mismatch
    2. return 304 if matched

Guidance

  • MAY supply ETag to cache the response

Implementation Detail

  • There are two kinds of ETag: Weak ETag and Strong ETag.
  • In express (nodejs web server framework), it would generate weak ETag by default; could generate strong ETag by changing the configuration
    • weak ETags are generated using CRC32 (source) and strong ETags are generated using MD5 (source).
  • In gin (golang web server framework), ETag could be generated via a middleware.

Reference