How does HTTP caching work in REST APIs with ETag and Cache-Control?

Answer

HTTP caching reduces server load and latency. Cache-Control headers set caching policy: Cache-Control: public, max-age=3600 allows any cache to store the response for one hour. ETag is a hash of the response body (e.g., ETag: "abc123"). On subsequent requests, the client sends If-None-Match: "abc123"; if the resource has not changed, the server returns 304 Not Modified (no body), saving bandwidth. Last-Modified is a timestamp alternative to ETag, used with If-Modified-Since. For user-specific data, use Cache-Control: private to prevent shared caches from storing it. Cache-Control: no-store prevents all caching (for sensitive data). Proper caching can dramatically reduce API load — up to 90% of traffic can be served from cache for read-heavy APIs.