Skip to content

Designing a RESTful API

Beginning of the lesson

Designing a RESTful API

Turning data into a clean, predictable set of URLs and verbs

Big idea: A REST API is a design style for HTTP services. Instead of inventing one function name per action, you model your data as resources (nouns), give each resource a stable URL, and use the standard HTTP verbs (GET, POST, PUT, PATCH, DELETE) to act on them. The result is an interface any developer can predict without reading a manual.
By the end you will be able to:
  • model data as resources and design their URLs,
  • map HTTP verbs to create/read/update/delete, and know which are safe or idempotent,
  • return the right status codes for success and failure,
  • explain why REST is stateless and design around it.

1. Resources: model nouns, not actions

The heart of REST is the resource: a thing your system knows about, such as a task, a user, or an order. A resource is a noun. The mistake beginners make is designing around verbs — /createTask, /getTask, /deleteTask — which means every new action needs a new URL and every client must memorise them.

In REST you flip that around. You expose one URL per resource and let the HTTP method describe the action:

  • a collection lives at a plural path: /tasks
  • a single item lives under it by id: /tasks/42

Analogy. Think of a filing cabinet. /tasks is the drawer labelled "Tasks"; /tasks/42 is one folder inside it. You never label a drawer "open the tasks drawer" — the drawer is a noun, and opening, adding, or removing folders are separate actions you perform on it. HTTP verbs are those actions.

2. HTTP verbs: one method, one intent

HTTP defines a small set of verbs, each with an agreed meaning. A well-designed API uses them exactly as intended so clients, proxies, and caches can reason about a request without reading its body.

VerbTypical useOn /tasksOn /tasks/42
GETReadlist all tasksfetch task 42
POSTCreatecreate a new task(rarely used)
PUTReplace(rarely used)replace task 42 wholesale
PATCHPartial update(rarely used)change some fields of task 42
DELETERemove(rarely used)delete task 42

Two properties matter when choosing a verb:

  • Safe — the request does not change server state. GET is safe; it should never create or delete anything. This is why a browser can prefetch links freely.
  • Idempotent — sending the same request twice leaves the server in the same state as sending it once. GET, PUT, and DELETE are idempotent; POST is not (two POSTs create two tasks).

PUT vs PATCH trips people up: PUT replaces the whole resource (fields you omit are cleared), while PATCH changes only the fields you send. Choose PATCH when a client wants to flip one flag without resending the entire object.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers