What makes an API good? Principles of API design

Difficulty: Beginner

Question

What qualities make an API well designed, and how would you judge one in a design review?

Answer

Think of an API as a user interface whose users happen to be programmers. Just like a good app UI, a good API is judged by how quickly a stranger can accomplish a task without reading a manual. That framing is the one interviewers love, because it moves the conversation away from memorising rules and towards reasoning about the consumer.

The first quality is consistency. If one endpoint returns createdAt and another returns created_at, or one paginates with page and the next with offset, every integrator pays a tax. Pick conventions for naming, casing, date formats (ISO 8601 in UTC), pagination and error shapes, and stick to them everywhere. Stripe is the usual example: once you have learned one resource, the rest feel predictable.

The second is the principle of least surprise. A GET must never change state, a DELETE on something already deleted should not explode, and a field named amount should say whether it is in rupees or paise. Ambiguity is where production bugs live, so be explicit: store money as integer minor units with a currency code, never as floating point.

Third is simplicity and focus. Model the domain the consumer cares about, not your database tables. If clients must call five endpoints and stitch results to render one screen, the API is leaking your internal structure. Good APIs expose stable business concepts such as orders, payments and refunds, and hide the messy storage behind them.

Fourth is evolvability. You will be wrong about something, and clients you do not control will depend on it. Design so that you can add fields, add optional parameters and add new enum values without breaking anyone, and have a versioning and deprecation policy before you need it. Tell consumers to ignore unknown fields, and avoid making response shapes depend on undocumented behaviour.

Fifth is safety and reliability under real conditions. Networks fail, clients retry, and users double click. So think about idempotency for writes, rate limits with clear headers, timeouts, and meaningful error responses that say what went wrong and whether retrying helps. Security is part of design too: authenticate every call, authorize per resource, validate input, and never leak internals in error messages.

Sixth is discoverability and documentation. An OpenAPI spec, runnable examples, sandbox keys and a changelog are part of the product. If your docs and behaviour disagree, developers trust neither. Good error messages that link to docs count as documentation as well.

Finally, performance and ergonomics: sensible pagination defaults, the ability to filter and select fields, compression, and caching headers. Do not optimise prematurely, but do not ship an endpoint that returns a million rows either.

In a review, I would run a quick checklist: are names consistent, are methods used with correct semantics, are status codes accurate, is every list paginated, are writes safe to retry, is there a versioning story, and can a new developer make a first successful call in under ten minutes. That last one, time to first successful call, is a surprisingly good metric that companies like Stripe and Postman openly optimise for.

Code examples

Consistent resource shape

GET /v1/orders/ord_123 HTTP/1.1
Accept: application/json

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "ord_123",
  "status": "paid",
  "amount": 49900,
  "currency": "INR",
  "created_at": "2026-09-01T10:15:30Z"
}

Integer minor units, an explicit currency, ISO 8601 UTC timestamp, and a prefixed id that hints at the resource type.

Key points

Common follow-up questions

Interview tips

Concepts covered

API design, consistency, developer experience, least surprise

More API Design questions