Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Return structured JSON data with a consistent response shape.
Sending JSON Responses is easiest to learn by reading the example, changing it, and observing the result.
import express from 'express';
const app = express();
app.use(express.json()); // JSON bodies
app.use(express.urlencoded({ extended: true })); // HTML form bodies
app.post('/api/lessons', (req, res) => {
const { title } = req.body;
res.status(201).json({ title, created: true });
});
app.listen(3000);Practice the Sending JSON Responses example in a small scratch file, then explain what changed and why.