From one route to a real API

Your bookstore server has one route. Now the product team wants list, get, create, and delete. You could pile every handler into the same file and it would work for a while. Then someone asks for authors, categories, and search, and you are staring at a single file no one wants to touch.

REST is a convention, not a protocol. The convention is simple: model your data as resources (books, users, orders) and use HTTP verbs as actions. Anyone who sees the URL knows what it does, without reading docs.

The standard mapping for a resource called books: GET /api/books lists them, GET /api/books/:id fetches one, POST /api/books creates one, DELETE /api/books/:id removes one. Status codes follow the same convention: 200 for success, 201 for created, 204 for deleted, 404 for not found, 400 for bad input.

REST verbs against one resource

Same path, different verbs, different actions.

Quiz: Quiz

Loading practice…