Requests and responses
Send JSON with one naming style, exact dates, safe money values and string IDs, so every field means the same thing everywhere in the API.
- Required 4
- Recommended 8
- Optional 1
Required
Send money as an integer with its currency
API-8Send amounts as an integer count of the currency's smallest unit, together with the ISO 4217 currency code. Never use floating-point numbers for money.
Accept only fields you know
API-12Validate every request body, query parameter and path parameter against its schema at the edge. Reject unknown fields and wrong types with a clear error.
Set caching headers on every response
API-14Send an explicit
Cache-Controlheader on every API response. Sendno-storeon any API response with personal or account data.Cap the size of every request body
API-93Set a byte limit on the body of every endpoint, such as 1 MB for JSON. Stop reading at the limit and answer 413 Content Too Large.
Recommended
Use JSON with one naming style
API-6Send and accept JSON with
Content-Type: application/json, and name every field in one style across the whole API.Send dates as RFC 3339 with a time zone
API-7Write every moment in time as an RFC 3339 string with a zone or offset. Write a calendar date with no time as
YYYY-MM-DD.Send IDs as strings
API-9Type every ID as a string, even when it looks like a number today.
Give every response one shape
API-10Return the same fields of the same types every time, and describe them in the contract. Leave out a field only when the contract says it is optional.
Use enums for fixed values
API-11Give every field with a fixed set of values an enum in the contract, and document what each value means.
Say which format PATCH accepts
API-13Accept PATCH bodies in one documented patch format, and name it in the
Content-Typeheader.Stream in a standard format and describe each item
API-15When an answer arrives in parts, stream it as server-sent events or as JSON Lines. Describe each item with
itemSchemain the OpenAPI contract.Reject JSON with duplicate keys
API-92Refuse any request body in which one object holds the same key twice. Answer 400 with problem details that name the key.
Optional
Let clients ask for only the fields they need
API-94When records carry large or costly fields, let clients pick the fields to return with one
fieldsparameter. Let them embed related records with oneexpandparameter, capped at one level.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/requests-and-responses">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.