DevAcademy
LearnNode.jsREST API Design
IntermediateNode.js

REST API Design

Conventions for structuring resources, URLs, and status codes in a predictable, RESTful API.

Reading Time

14 min

Lesson

Lesson 25 of 34

Resources, Not Actions

A RESTful API models URLs around resources (nouns), and uses HTTP methods to express the action — rather than encoding the verb into the URL itself. /users is a resource; GET, POST, PUT, and DELETE against it are the actions.

Standard REST Conventions

Method + URLAction
GET /usersList all users
GET /users/:idGet a single user
POST /usersCreate a new user
PUT /users/:idReplace a user entirely
PATCH /users/:idPartially update a user
DELETE /users/:idDelete a user

A Bad vs Good URL Design

# Avoid: verbs baked into the URL
POST /createUser
GET /getUserById?id=42

# Prefer: resources + HTTP methods
POST /users
GET /users/42

Nested Resources

When one resource clearly belongs to another, nest it in the URL: /users/42/orders lists orders belonging to user 42. Avoid nesting more than one or two levels deep — it quickly becomes unwieldy.

Choosing the Right Status Code

SituationStatus Code
Successful GET200 OK
Successful POST creating a resource201 Created
Successful DELETE204 No Content
Invalid request data400 Bad Request
Not authenticated401 Unauthorized
Authenticated but not allowed403 Forbidden
Resource does not exist404 Not Found

PUT vs PATCH

PUT conventionally replaces the entire resource — fields you omit are expected to be reset. PATCH updates only the fields provided, leaving everything else untouched. Many real-world APIs use PATCH more often than strict REST purism would suggest, since it matches how forms actually submit partial edits.

Best Practice

Version your API from the start (e.g. /api/v1/users) — it costs almost nothing upfront and gives you a clean path to make breaking changes later without disrupting existing clients.

Interview Questions

Quick Quiz

1. What is the RESTful convention for a URL, per the guidance in this lesson?

2. What status code conventionally indicates a resource was successfully created?

3. What is the conventional difference between PUT and PATCH?