Express.js — Basic Routes & HTTP Methods

🚀 Express 5.0+ 🟢 Chapter 6 of 50 📂 Phase 02: Core Routing & Parameters 📅 2026 Edition
📌 Covered in this chapter: HTTP Routing · GET · POST · PUT · PATCH · DELETE · Route Paths · Catch-All 404 Handlers · Execution Order

Welcome to Express.js — Basic Routes & HTTP Methods in our Express.js Complete Masterclass! Define HTTP verb endpoints (GET, POST, PUT, DELETE) and handle 404 unknown routes.

1Core Architectural Concepts of Basic Routes & HTTP Methods

HTTP routing determines how an Express application responds to client requests at specific URIs using methods like GET, POST, PUT, PATCH, and DELETE. A catch-all 404 middleware registered at the end of the stack captures all unmatched route requests.

2Key Technical Objectives & Specs
📚 Technical Learning Specs:
  • Master the underlying Node.js event loop mechanics for Basic Routes & HTTP Methods.
  • Implement non-blocking, asynchronous execution pipelines in compliance with production API standards.
  • Enforce strict OWASP Top 10 API security guidelines and performance optimizations.
3Technical Specification Matrix
HTTP VerbPrimary PurposeIdempotentRequest Body
GETRetrieve resources without side effectsYesNo
POSTCreate a new resource recordNoYes
PUTReplace an existing resource completelyYesYes
PATCHApply partial updates to a resourceNoYes
DELETERemove a specific resource recordYesOptional
4Basic Code Implementation
JavaScript / Express.js — Basic Basic Routes & HTTP Methods
import express from 'express';
const app = express();
app.use(express.json());

app.get('/courses', (req, res) => res.json([{ id: 1, title: 'Express' }]));
app.post('/courses', (req, res) => res.status(201).json({ id: 2, ...req.body }));
app.put('/courses/:id', (req, res) => res.json({ id: req.params.id, updated: true }));
app.delete('/courses/:id', (req, res) => res.json({ id: req.params.id, deleted: true }));

// 404 Catch-All Handler
app.use((req, res) => {
  res.status(404).json({ error: 'Resource Not Found' });
});
5Production Implementation & Architecture Pattern
JavaScript / Express.js — Production Basic Routes & HTTP Methods
// RESTful Compliance Controller
import express from 'express';
const app = express();

app.patch('/api/v1/users/:id', (req, res) => {
  res.status(200).json({ message: 'User partial fields updated successfully' });
});

app.listen(3000);
6Internal Execution Engine Pipeline
Incoming Request -> Route Matching Engine (FIFO order) -> Match Found? Execute Handler : Trigger 404 Middleware
7Common Developer Anti-Patterns & Security Pitfalls
⚠️ Anti-Patterns to Avoid
  • Placing dynamic wildcard routes above static routes, causing static endpoints to be swallowed.
  • Using GET requests for state-mutating actions like database deletion.
8Frequently Asked Technical Interview Questions (Q&A)

❓ Question: Difference between PUT and PATCH?

Answer: PUT requires submitting the complete resource object to replace existing data. PATCH accepts partial field updates without modifying unspecified attributes.

❓ Question: Why is route order crucial in Express?

Answer: Express evaluates routes sequentially from top to bottom. If a broad wildcard route is placed at the top, subsequent routes will never be reached.

9Hands-On Practical Engineering Challenge
🎯 Hands-On Challenge:

Create CRUD endpoints for a `/books` resource (GET, POST, PUT, DELETE) and append a 404 fallback handler returning JSON.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on Express 5.0+ Standards · Last updated August 2026