← Back to Node.js Course | Chapter 8: Working with APIs | Lesson 1 of 7

REST API basics

REST is a style for designing APIs around resources with URLs and standard HTTP methods.

In this page:

  1. REST API basics

REST API basics

Resources are nouns such as /users and /users/42. Methods express actions: GET reads, POST creates, PUT or PATCH updates and DELETE removes. Responses use JSON and meaningful status codes. Stateless requests make APIs easy to scale.

Note: Use plural nouns for collections.

Example: REST API basics

javascript
const routes = [
  ["GET", "/users", "list users"],
  ["POST", "/users", "create a user"],
  ["GET", "/users/:id", "read one user"],
  ["PATCH", "/users/:id", "update a user"],
  ["DELETE", "/users/:id", "delete a user"],
];
for (const [m, p, d] of routes) console.log(m.padEnd(6), p.padEnd(11), d);

// Output:
// GET    /users      list users
// POST   /users      create a user
// GET    /users/:id  read one user
// PATCH  /users/:id  update a user
// DELETE /users/:id  delete a user

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
Common Mistakes
  1. Putting verbs in URLs like /getUsers
  2. Ignoring status codes
  3. Storing session state on the server
Chapter Summary
  • Resources are nouns
  • HTTP methods are the verbs
  • JSON responses
  • Stateless requests
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.