Adding ETags to API responses
An Entity Tag (ETag) is an HTTP response header that contains a computed hash or equivalent value of the response entity and a minor change in the entity must change its value. HTTP request objects can then contain the If-None-Match
and If-Match
headers for receiving the conditional responses.
Let's call an API for retrieving the response with an ETag as shown next:
$ curl -v --location --request GET 'http://localhost:8080/api/v1/products/6d62d909-f957-430e-8689-b5129c0bb75e' –header 'Content-Type: application/json' --header 'Accept: application/json' Note: Unnecessary use of -X or --request, GET is already inferred. * Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 8080 (#0) > GET /api/v1/products/6d62d909-f957-430e-8689-b5129c0bb75e HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.55.1 > Content-Type: application/json > Accept: application...