REST, HTTP Methods and Endpoints

6.Nouns, Verbs and a Library Catalogue

A

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.

14–16 min

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."

A

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/events is the collection of events; /api/events/42 is one event, number 42; /api/events/42/seats is the seats belonging to event 42.
  • HTTP methods are verbs — the actions: instead of putting actions in the URL (like /api/getEvent or /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 OK for a successful read, 201 Created after a POST, 204 No Content after a successful DELETE, 400 for bad input, 404 if 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).
Table — BlueTicket's API, the REST way
EndpointIn plain EnglishSuccess code
GET /api/eventsList all events200
GET /api/events/42Show event 42200
GET /api/events/42/seatsList the seats of event 42200
POST /api/holdsCreate a new hold (seat in the body)201
DELETE /api/holds/h_9182Cancel hold h_9182204
PATCH /api/fans/77Change part of fan 77's profile200
POST /api/bookingsCreate a booking (pay)201
Table — REST style vs. action-in-the-URL style
Not RESTREST
GET /api/getEvent?id=42GET /api/events/42
POST /api/createHoldPOST /api/holds
POST /api/deleteHold?id=h_9182DELETE /api/holds/h_9182
POST /api/updateFanPhonePATCH /api/fans/77
Table — Safe to repeat?
RequestSent twice by accidentSafe to repeat?
GET /api/events/42Same event shown twiceYes
PUT /api/fans/77 (whole profile)Same profile saved twiceYes
DELETE /api/holds/h_9182Still deletedYes
POST /api/bookingsTwo bookings — charged twice!No — needs protection (Act 23)
This whole line is a row — one record

Reading a REST endpoint as a sentence

GET

the verb — read

what to do it to

/api/events/42

the noun — event number 42

narrowed down

/seats

the seats that belong to it

response

200 OK + JSON list of seats

the result

Being an API client from the terminal with curl
# Read event 42 (GET is the default)
curl https://blueticket.example/api/events/42
# Create a hold: POST with a JSON body
curl -X POST https://blueticket.example/api/holds \
-H "Content-Type: application/json" \
-d '{"seatId": "C14"}'
# Cancel it
curl -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.