Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Add types to req, res, params, and bodies.
Typing Requests and Responses is easiest to learn by reading the example, changing it, and observing the result.
// npm install --save-dev typescript @types/express
import express, { Request, Response } from 'express';
interface Lesson { slug: string; title: string; }
const app = express();
app.get('/api/lessons/:slug', (req: Request, res: Response) => {
const lesson: Lesson = { slug: req.params.slug, title: 'Typed lesson' };
res.json(lesson);
});
app.listen(3000);Practice the Typing Requests and Responses example in a small scratch file, then explain what changed and why.