// First request - creates user
const response = await fetch("/api/v1/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(), // e.g. "idx_abc123"
},
body: JSON.stringify({ email: "user@example.com", name: "John" }),
});
// Same key - returns cached response (no duplicate creation)
const retry = await fetch("/api/v1/users", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Idempotency-Key": "idx_abc123", // Same key!
},
body: JSON.stringify({ email: "user@example.com", name: "John" }),
});