REST API (Node.js)
A REST API in Node.js exposes resources over HTTP using JSON and standard verbs — GET to read, POST to create, PUT/PATCH to update, DELETE to remove. It is commonly built with Express routes that return res.json().
Node.js
REST organizes an API around resources addressed by URLs, with the HTTP method expressing the action. /users is the collection, /users/:id is one item; GET reads, POST creates, PUT/PATCH updates, and DELETE removes. Clients exchange JSON, and you return appropriate status codes (200, 201, 404, 400).
In Express you implement each as a route: app.get('/users', ...), app.post('/users', ...), app.get('/users/:id', ...), and so on, reading input from req.params/req.query/req.body and replying with res.status(code).json(data). Routers split resources into separate files as the API grows.
Production APIs add layers around this skeleton: a body parser (express.json()), input validation, authentication (commonly JWT), consistent error handling, CORS for browser clients, and a database via a driver or ORM like Mongoose or Prisma.
Syntax
app.get("/users/:id", (req, res) => res.json(user))Examples
JavaScript
const users = [{ id: 1, name: "Ana" }];
app.get("/users", (req, res) => res.json(users));
app.post("/users", (req, res) => {
const u = { id: users.length + 1, ...req.body };
users.push(u);
res.status(201).json(u);
});