Typorithm · medium

REST API Design

rest-designnodejsresthttp-verbsstatus-codes
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn REST API Design

0%

API Patterns

REST models resources as nouns acted on by HTTP verbs — GET to read, POST to create, PATCH to update, DELETE to remove — returning proper status codes (200/201/404/422). Collections support pagination and filtering, APIs are versioned (/v1), and safe methods stay idempotent.

REST treats your domain as resources named by nouns — /users, /users/:id — and uses HTTP verbs to act on them: GET reads, POST creates, PATCH updates, DELETE removes. The URL identifies the thing; the verb says what to do.

Return meaningful status codes: 200 for a successful read, 201 for a create, 404 when a resource does not exist, and 422 for input that fails validation. The status is part of the API contract.

Collection endpoints should support pagination and filtering via query params, and APIs are versioned (e.g. /v1) so changes do not break clients. Safe and idempotent methods (GET, DELETE) can be retried without side effects.

01

Resources are nouns; HTTP verbs are the actions.

02

Use proper status codes: 200/201/404/422.

03

Version the API and paginate collections.

GET    /users        # list
POST   /users        # create
GET    /users/:id    # read
PATCH  /users/:id    # update
DELETE /users/:id    # delete

Read the implementation

Connect each part of the code to the concept before you type.

1. List a collection

GET on a collection returns the list of resources; it is a safe, read-only verb.

GET    /users        # list

2. Create a resource

POST to a collection creates a new resource, conventionally returning 201 Created.

POST   /users        # create

3. Read one

GET on a single resource path reads that one item, or returns 404 if it is missing.

GET    /users/:id    # read

4. Update a resource

PATCH applies a partial update to an existing resource identified by its id.

PATCH  /users/:id    # update

5. Delete a resource

DELETE removes the addressed resource; repeating it is idempotent.

DELETE /users/:id    # delete

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

REST API Design: Lesson & Practice · Typorithm | ApplyDjinn