In this chapter
We'll learn REST, the most common way to design web APIs — resources as nouns in the URL, HTTP methods as verbs — plus what an endpoint is, and the difference between API clients and API servers, using a library's catalogue as our picture.
The Problem in Real Life
Anna writes down every /api/ path she saw today: GET /api/events, GET /api/events/42, GET /api/events/42/seats, POST /api/holds, DELETE /api/holds/h_9182. They look tidy, almost like a pattern somebody planned.
"Somebody did plan it," John says. "Once you see the pattern, you can guess almost any endpoint in our API — or in thousands of other companies' APIs — without reading the documentation."
The paths are things, and the methods are actions. Is that the whole trick?
Anna
Random Paths vs. a Predictable Design
APIs need a shape
Without agreed rules, every API would invent its own names and nobody could guess anything.
Things and actions
A good API separates what you're working with (the thing) from what you're doing to it (the action).
Many clients, one server
Browsers, apps and tools all call the same API server in the same way.
REST, HTTP Methods, Endpoints, API Clients and API Servers
The library catalogue analogy: in a library, every book has a place in a predictable system: section, shelf, number. You can borrow a book, return it, or ask the librarian to add a new one. You don't need a different procedure for every book — the same few actions work on everything. REST (Representational State Transfer) designs APIs the same way.
- Resources are nouns — the books: in REST, everything the API works with is a resource: an event, a seat, a hold, a booking, a fan. Each resource has its own URL, written with nouns, usually plural:
/api/eventsis the collection of events;/api/events/42is one event, number 42;/api/events/42/seatsis the seats belonging to event 42. - HTTP methods are verbs — the actions: instead of putting actions in the URL (like
/api/getEventor/api/deleteHold), REST uses the HTTP methods from Act 11 as the verbs. GET reads, POST creates, PUT replaces, PATCH updates part of something, DELETE removes. The same five verbs work on every resource. - Status codes are the results: REST APIs use the HTTP status codes to say what happened:
200 OKfor a successful read,201 Createdafter a POST,204 No Contentafter a successful DELETE,400for bad input,404if the resource doesn't exist. - Stateless, like HTTP: each REST request carries everything needed to understand it — including who's asking (the cookie or a token, chapter 4). The server doesn't depend on what happened in earlier requests. That's what lets BlueTicket run many identical servers side by side (Act 14).
| Endpoint | In plain English | Success code |
|---|---|---|
| GET /api/events | List all events | 200 |
| GET /api/events/42 | Show event 42 | 200 |
| GET /api/events/42/seats | List the seats of event 42 | 200 |
| POST /api/holds | Create a new hold (seat in the body) | 201 |
| DELETE /api/holds/h_9182 | Cancel hold h_9182 | 204 |
| PATCH /api/fans/77 | Change part of fan 77's profile | 200 |
| POST /api/bookings | Create a booking (pay) | 201 |
| Not REST | REST |
|---|---|
| GET /api/getEvent?id=42 | GET /api/events/42 |
| POST /api/createHold | POST /api/holds |
| POST /api/deleteHold?id=h_9182 | DELETE /api/holds/h_9182 |
| POST /api/updateFanPhone | PATCH /api/fans/77 |
| Request | Sent twice by accident | Safe to repeat? |
|---|---|---|
| GET /api/events/42 | Same event shown twice | Yes |
| PUT /api/fans/77 (whole profile) | Same profile saved twice | Yes |
| DELETE /api/holds/h_9182 | Still deleted | Yes |
| POST /api/bookings | Two bookings — charged twice! | No — needs protection (Act 23) |
Reading a REST endpoint as a sentence
GET
the verb — read
/api/events/42
the noun — event number 42
/seats
the seats that belong to it
200 OK + JSON list of seats
the result
# Read event 42 (GET is the default)curl https://blueticket.example/api/events/42# Create a hold: POST with a JSON bodycurl -X POST https://blueticket.example/api/holds \-H "Content-Type: application/json" \-d '{"seatId": "C14"}'# Cancel itcurl -X DELETE https://blueticket.example/api/holds/h_9182
-X sets the method, -H adds a header, -d sends a request body. A backslash at the end of a line continues the command on the next line.
Endpoint — one entry in the catalogue: an endpoint is one specific combination of method and URL that the API supports: GET /api/events/42 is one endpoint; DELETE /api/holds/{holdId} is another. An API's documentation is mostly a list of its endpoints, each with what to send and what comes back.
API server and API client — the library and the readers: the API server is the program that receives API requests and answers them — BlueTicket's backend. An API client is anything that sends API requests: the JavaScript in BlueTicket's web pages, the mobile apps, a partner's website, or a developer testing by hand with tools like curl in the terminal or Postman, a desktop app for trying out APIs. All clients call the same endpoints the same way.
Reading the pattern: Anna tests herself. "How do I get all the bookings for fan 77?" — GET /api/fans/77/bookings. "How do I change just the phone number of fan 77?" — PATCH /api/fans/77 with { "phone": "..." } in the body. "How do I cancel hold h_9182?" — DELETE /api/holds/h_9182. John checks the API documentation. All three exist, exactly as she guessed.
One more useful idea — safe to repeat: some requests can be sent twice with no extra effect. Reading an event twice changes nothing; deleting the same hold twice still leaves it deleted. Others can't: sending POST /api/bookings twice could create two bookings — and charge the fan twice. This difference matters a lot when networks are slow and users click twice, and it comes back with payments in Act 23.
Key Takeaway
REST designs APIs like a library catalogue: resources are nouns in the URL (/api/events/42/seats), HTTP methods are the verbs (GET read, POST create, PUT replace, PATCH update, DELETE remove), and status codes report the result. An endpoint is one method plus one URL. The API server answers; API clients — web pages, apps, partners, curl, Postman — all call it the same way.
Why This Matters
REST is the shape of most web APIs in the world — payment providers, maps, email services, social networks, and BlueTicket's own. If you understand nouns, verbs and status codes, you can read almost any API's documentation in minutes, and design APIs that other developers can guess. It's the foundation for Act 23's integrations and for every backend job.
Anna now understands the whole web, from the key press to the page, the cache, the cookie and the API. John has one last test for this Act: tell the full story of one ticket purchase, from start to finish, using everything from Acts 11 and 12.
