REST API basics
REST is a style for designing APIs around resources with URLs and standard HTTP methods.
In this page:
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
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
- Putting verbs in URLs like /getUsers
- Ignoring status codes
- 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: