Updates the document only if the client's ETag is current
PUT
https://api.testingapis.com/api/cache/etagRequires If-Match with the current ETag (strong comparison, so W/ tags never match; * matches). A successful update increments the version and returns the new ETag. Use it to test lost-update protection.
Note: Send the current ETag (from GET /api/cache/etag) in If-Match. Missing -> 428, stale -> 412.
Parameters 1
| Name | Type | Description |
|---|---|---|
If-Match | header · string | Current ETag. Missing returns 428, stale returns 412. |
Request body
Optional. application/json, text/json, application/*+json, application/xml, text/xml, application/*+xml. Model: CachingControllerDocumentUpdate. New title and/or content.
Example body
{"title": "Updated title", "content": "New content"}Responses
- 200
- Updated; the new ETag is in the header and body.
- 400
- Neither title nor content supplied, or malformed body.
- 412
- If-Match does not match the current ETag.
- 428
- If-Match header missing.
Example
Request
curl -X PUT "https://api.testingapis.com/api/cache/etag" \
-H "Content-Type: application/json" \
-H "If-Match: "doc-v1"" \
-d '{"title": "Updated title", "content": "New content"}'Response200 OK
ETag: "doc-v2"
{
"message": "Document updated",
"data": {
"id": 1,
"version": 2,
"title": "Updated title",
"content": "New content",
"updatedAt": "2026-09-30T18:26:44Z",
"etag": "\"doc-v2\""
}
}Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/cache/etag", {
method: "PUT",
headers: {
"Content-Type": "application/json",
"If-Match": "doc-v1",
},
body: "{\"title\": \"Updated title\", \"content\": \"New content\"}",
});
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"PUT",
"https://api.testingapis.com/api/cache/etag",
headers={
"Content-Type": "application/json",
"If-Match": "doc-v1",
},
data="{\"title\": \"Updated title\", \"content\": \"New content\"}".encode("utf-8"),
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"))
.header("Content-Type", "application/json")
.header("If-Match", "doc-v1")
.method("PUT", HttpRequest.BodyPublishers.ofString("{\"title\": \"Updated title\", \"content\": \"New content\"}"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}