New in 2.4: Test runs you can trust See what's new →

Returns the versioned document with its ETag

GETHEADhttps://api.testingapis.com/api/cache/etag

Reads If-None-Match: when it matches the current ETag (weak comparison, * matches anything), the response is 304 with no body. The ETag has the form "doc-v{version}". Also answers HEAD.

Note: Send the returned ETag back in If-None-Match to get 304 Not Modified.

Parameters 1

NameTypeDescription
If-None-Matchheader · stringETag from a previous response; a match returns 304 Not Modified.

Responses

200
The document, with ETag and Cache-Control: no-cache.
304
The client's copy is current.

Example

Request
curl -X GET "https://api.testingapis.com/api/cache/etag"
Run in Studio
Response200 OK
ETag: "doc-v1"
Cache-Control: no-cache

{
  "id": 1,
  "version": 1,
  "title": "TestingAPIs cached document",
  "content": "Send If-None-Match to get a 304, and If-Match on PUT to make a conditional update.",
  "updatedAt": "2025-01-01T00:00:00Z",
  "etag": "\"doc-v1\""
}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/cache/etag");
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "GET",
    "https://api.testingapis.com/api/cache/etag",
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/cache/etag"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}