Skip to the guide

Designing a REST API

BeginnerConcept3 pages

An API is the list of requests your service promises to answer, and the shape of each answer. In most interviews you sketch one right after the requirements: a handful of endpoints the rest of the design has to serve. REST is the default style, and interviewers judge it quickly. Are the URLs clean, are the methods right, and what happens when the same request arrives twice?

A library desk

In a library, every book has a catalogue number, and the number finds the book wherever it sits. At the desk you can make only a few kinds of request, and they work the same for every book: let me see it, add this new one, replace this copy, take it off the shelf. The librarian answers with a standard stamp: here it is, we don't have it, you're not allowed. And the desk doesn't remember your last visit, so each slip you hand over says everything needed.

  • the catalogue number → a URL that names a resource: /posts/42
  • the librarian → the API server, which fetches from the shelves, your database
  • the few kinds of request → the HTTP methods: GET, POST, PUT, PATCH, DELETE
  • the standard stamp → the status code: 200, 404, 403
  • a desk with no memory → stateless requests: each one carries its own credentials and details