Spunk Autos

Websites and web tools

API Design: Myth vs Fact

Many API design arguments come from rules repeated without their reasons. This page takes eight common beliefs and checks each one against how HTTP and well-run APIs actually behave. It is aimed at developers building small APIs, such as a booking endpoint for a repair shop or a stock feed for a dealer site.

Myths about methods

Myth: POST is for anything that changes data

Fact: POST is the general choice for creating something or triggering an action, but HTTP gives more specific methods. PUT replaces a resource at a known URL, PATCH applies a partial change, and DELETE removes it. Using them lets clients and proxies reason about retries.

Myth: retries are always safe

Fact: only idempotent requests can be repeated without side effects. GET, PUT and DELETE are defined as idempotent; POST is not. If a booking POST times out and the client retries, the customer may get two appointments. A common fix is an idempotency key header that the server stores, so a repeated request returns the first result instead of creating a duplicate.

Myths about status codes

Myth: return 200 and put the error in the body

Fact: status codes exist so clients, monitors and caches know what happened without parsing the body. Use 400 for a malformed request, 401 when authentication is missing, 403 when the caller is known but not allowed, 404 for a missing resource, 409 for a conflict such as a double-booked slot, 422 for valid syntax that fails validation, and 5xx only for server faults.

Myth: the status code alone is enough

Fact: clients also need a consistent error body. A small structure with a machine-readable code, a human message and the field at fault makes errors easy to display. RFC 9457, problem details for HTTP APIs, defines one widely used format.

Myths about structure

Myth: every API must be RESTful to be good

Fact: REST is one style. RPC-style endpoints and GraphQL are valid choices with different trade-offs. What matters more is consistency: the same naming, the same date format, the same pagination and the same error shape across every endpoint.

Myth: versioning can wait until later

Fact: adding a version after clients exist is painful. Decide on day one how breaking changes will be handled, whether through a path segment such as /v1/, a header, or a promise to only make additive changes. Adding a new optional field is usually safe; renaming or removing one breaks clients.

Myth: returning everything is simpler

Fact: an unpaginated list works with 30 records and fails with 30,000. Paginate list endpoints from the start, using a cursor or an offset and limit, and return a link or token for the next page.

Myth: IDs should be sequential numbers

Fact: sequential IDs are compact but reveal how many records exist and invite guessing. Random identifiers such as UUIDs avoid that. Either way, authorisation must be checked on every request; an unguessable ID is not access control.

Summary table

BeliefBetter practice
POST for every changeMatch the method to the action
200 with error textCorrect status plus a structured error body
Version laterChoose a versioning rule before launch
Return the full listPaginate from the start
Hidden IDs are securityCheck permissions on every request