Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Read and validate optional query parameters from req.query.
Query Strings is easiest to learn by reading the example, changing it, and observing the result.
import express from 'express';
const app = express();
// GET /api/lessons/express-routing?fields=title
app.get('/api/lessons/:slug', (req, res) => {
const { slug } = req.params; // dynamic URL segment
const { fields } = req.query; // ?fields=title
res.json({ slug, fields: fields ?? 'all' });
});
app.listen(3000);Practice the Query Strings example in a small scratch file, then explain what changed and why.