AlgoViz

API design introduction

easy 24 min

An API is a contract: it says what a program may ask for and what it gets back, and it hides how the work is done.

Remember it

The few things worth knowing cold, and how to make them stick.

Memory hook

WAITER: the API is your waiter between client and server.

A restaurant. The menu is the documentation, the order is the request, the waiter is the endpoint, the kitchen is the server, the dish is the response, the reservation is authentication.

Cheat sheet

URL
the noun
Method
the verb
Status
2 worked, 4 you, 5 us
Methods
GET read, POST create, PUT replace, PATCH change, DELETE remove
Credentials
Authorization header
New resource
201 + Location
Too many calls
429 + Retry-After
Server steps
receive, authenticate, authorize, validate, process, respond

Spot it when you see

  • Two programs must work together without sharing a database.
  • Different clients need the same data.
  • Partners or strangers will build on it.
  • Teams want to change their own storage freely.

Tricks that stick

  • W web-based, A application interface, I intermediary, T transport by HTTP methods, E endpoints define resources, R request and response.
  • Request lifecycle, UBSSPRU: User action, Build request, Send, Server processes, Process query, Receive, Update UI.
  • CRUD with GPP-D: GET reads, POST creates, PUT updates, DELETE deletes.

Do not forget

  • Verbs in URLs.
  • GET that changes data.
  • 200 with an error inside.
  • Lists without a limit.
  • Exposing tables as they are.