SproutStackSproutStack home

API Design Basics

5 min readBeginner-friendlyFree to read

Before this, it helps to know: DNS, HTTP, TCP in 10 Minutes.

Read a little, play a little. No scary maths, and no rush.

Share:

APIs are promises to strangers

An API is a contract: "send me this shape, I'll return that shape, forever." Every breaking change breaks someone's app at 2 AM. Good API design is mostly about keeping promises cheap to keep.

The methods and what they mean

  • GET — read. Safe to retry, never changes anything.
  • POST — create. Not safe to retry blindly: two taps on "Pay" must not charge twice.
  • PUT — replace. Same result no matter how many times you send it (idempotent).
  • DELETE — remove. Deleting twice is fine — the thing is just gone.

That word, idempotent, is interview gold: "can I safely retry this?" For POST /payments, the answer comes from an Idempotency-Key header — the client generates one UUID per payment attempt, the server stores it, and a retried request with the same key returns the original receipt instead of charging again.

Lists: paginate or perish

Never GET /orders with no limits — one day that table has 10 million rows and your response is 800 MB. Instead:

GET /orders?cursor=eyJpZCI6MTAw&limit=50

The server returns 50 orders plus the next cursor. Cursors (not page numbers) stay stable when new rows arrive mid-scroll — page 2 of "page=2" shifts, cursors don't.

The boring parts that save interviews

  • Versioning: /v1/orders from day one, so v2 can exist without breaking v1.
  • Errors: { "code": "RATE_LIMITED", "message": "...", "retryable": true } — machines read code, humans read message.
  • Throttling: return 429 Too Many Requests with a Retry-After header instead of falling over.

A worked example: an orders API

  • GET /v1/orders?cursor=...&limit=50 lists the caller's orders, newest first.
  • GET /v1/orders/{id} returns one order, or 404 if it does not exist or belongs to someone else.
  • POST /v1/orders with an Idempotency-Key header creates an order and returns 201 Created with the new order.
  • POST /v1/orders/{id}/cancel cancels it. Canceling an order that has already shipped returns 409 Conflict with a clear error code, because the request is valid but the order's state does not allow it.

Each endpoint answers the questions a client developer will have: what can I retry, how do I page through results, and what does each failure mean.

Naming and data conventions

  • Resources are nouns, usually plural: /orders, /users/42. The method supplies the verb.
  • Nest sparingly. /users/42/orders is clear; four levels deep is a maze.
  • Timestamps in ISO 8601, in UTC: 2026-10-08T14:30:00Z. Let clients convert to local time.
  • Money as integers in the smallest unit plus a currency code: {"amount": 1999, "currency": "USD"}. Floating-point numbers cannot represent many decimal values exactly, and money is where that bites.
  • One casing style everywhere, such as snake_case or camelCase, never a mix.

REST, GraphQL, and gRPC

REST over JSON, as described here, is the default for public APIs because every language and tool understands it. GraphQL lets the client ask for exactly the fields it needs in one request, which suits apps with many different screens. gRPC uses a compact binary format and generated client code, which suits fast communication between internal services. Start with REST unless one of those needs is real.

Remember this

  • Retries are a fact of networks; design every endpoint assuming they happen.
  • Cursor pagination, idempotency keys, versioned paths — say all three and you sound senior.

Check your understanding

5 questions · first-try answers earn the most XP

1. Why are cursors preferred over page numbers for paginating a list that is still receiving inserts?
2. A client sends `POST /payments` twice because it never saw the first response. How do you stop a double charge?
3. Why version an API path from day one, even though it has never broken anyone?
4. Why should a rate-limited endpoint return 429 with a `Retry-After` header rather than simply failing?
5. Why should an error body carry both a machine code and a human message?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Practice this in an incident

Try a design drill

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.