REST APIs use HTTP methods (GET, POST, PUT, DELETE) to perform CRUD operations.
Getting Started
What is Node.js?
Modules & NPM
Modules & NPM
Process & Environment
Process & Environment Variables
Caching & Performance
Redis Caching
GraphQL with Node.js
GraphQL Basics
Node.js
Intermediate
FREE
REST API Design
Lesson 1 of 17
Intermediate
Interactive
Syntax
NODEJS
GET /api/users → List users GET /api/users/:id → Get user POST /api/users → Create user PUT /api/users/:id → Update user DELETE /api/users/:id → Delete user
REST API CRUD
NODE
const express = require("express"); const app = express(); app.use(express.json()); let items = []; let idCounter = 1; // GET all app.get("/items", (req, res) => res.json(items)); // GET one app.get("/items/:id", (req, res) => { const item = items.find(i => i.id === +req.params.id); item ? res.json(item) : res.status(404).json({ error: "Not found" }); }); // POST app.post("/items", (req, res) => { const item = { id: idCounter++, ...req.body }; items.push(item); res.status(201).json(item); }); // DELETE app.delete("/items/:id", (req, res) => { items = items.filter(i => i.id !== +req.params.id); res.json({ success: true }); });
Practice
1
Exercise
Practice this concept.
Answer
Write the code as shown above.
Quick Quiz
1
What did you learn?
This covers the basics.
Interview Questions
It is a fundamental Node.js feature.