Walkthrough
1. Define the contract
Document inputs, responses, authentication, error codes and retry behaviour.
2. Separate access from identity
A valid token establishes identity. The backend still decides whether the caller can access this order.
3. Make replay safe
For a create request, store the idempotency key with the request fingerprint and result. Reject reuse with different input.
Worked example
An order lookup uses GET. The server still checks that the caller is allowed to read that order.
| Method | Route | Purpose |
|---|---|---|
| GET | /orders/:id | Read an authorized order |
| POST | /orders | Create an order with safe replay |
| PATCH | /orders/:id | Update approved fields |
curl -X POST "$API_BASE/orders" \
-H "Authorization: Bearer $SERVICE_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-request-123" \
-d '{"sku":"SOFA-GRAY","quantity":1}'Show another code example
const response = await fetch(baseUrl + "/orders/order_demo", {
headers: { Authorization: "Bearer " + serviceToken },
});
if (!response.ok) throw new Error("Lookup failed: " + response.status);
const order = await response.json();