Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Fetch external data with axios and handle failures.
Calling Third-Party APIs is easiest to learn by reading the example, changing it, and observing the result.
// npm install axios
import express from 'express';
import axios from 'axios';
const app = express();
app.get('/api/weather/:city', async (req, res, next) => {
try {
const { data } = await axios.get('https://api.example.com/weather', {
params: { city: req.params.city },
timeout: 5000
});
res.json(data);
} catch (error) {
next(error);
}
});
app.listen(3000);Practice the Calling Third-Party APIs example in a small scratch file, then explain what changed and why.