AXTHORM

© AXTHORM

Developer library

Design an API

Use consistent resource names, validate the request, and check access to the specific record before reading or writing it.

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.

Methods for an example orders API
MethodRoutePurpose
GET/orders/:idRead an authorized order
POST/ordersCreate an order with safe replay
PATCH/orders/:idUpdate approved fields
cURL · illustrative
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
JavaScript · fetch
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();

Try it yourself

The client times out after POSTing an order. How should it retry?