Unit 1: Backend Architecture & Express RoutingLesson #2 / 4

Lesson 2: RESTful API Design & CRUD HTTP Methods

Er. Manoj Kumar — AuthorEr. Manoj KumarLast Updated: 26 Aug, 2026

1. REST API Architecture

REST (Representational State Transfer) defines standardized conventions for communication between frontend clients and backend servers using HTTP methods:

HTTP MethodCRUD ActionTypical Endpoint Route
GETRead/api/courses or /api/courses/:id
POSTCreate/api/courses
PUT / PATCHUpdate/api/courses/:id
DELETEDelete/api/courses/:id

2. Express CRUD Route Handlers

Code Example
import express from 'express';
const router = express.Router();
let courses = [
{ id: 1, title: 'HTML5 Foundations', free: true },
{ id: 2, title: 'CSS3 Layouts', free: true }
];
// GET: Fetch all
router.get('/api/courses', (req, res) => {
res.status(200).json(courses);
});
// POST: Create new
router.post('/api/courses', (req, res) => {
const newCourse = { id: Date.now(), ...req.body };
courses.push(newCourse);
res.status(201).json(newCourse);
});
// DELETE: Remove by ID
router.delete('/api/courses/:id', (req, res) => {
const { id } = req.params;
courses = courses.filter(c => c.id !== Number(id));
res.status(200).json({ message: 'Course deleted successfully' });
});
export default router;

Interactive Knowledge Check

Test your understanding of Lesson #2 concepts

Which HTTP status code signifies that a resource was successfully created on the server?