Recall & Review
beginner
What is API versioning and why is it important?
API versioning is a way to manage changes in an API over time. It helps keep old clients working while allowing new features or fixes in newer versions. This avoids breaking existing apps when the API changes.
Click to reveal answer
beginner
Name three common API versioning strategies used in Express apps.
1. URI versioning (e.g., /v1/users)<br>2. Query parameter versioning (e.g., /users?version=1)<br>3. Header versioning (using custom headers like 'Accept-Version')
Click to reveal answer
beginner
How does URI versioning work in Express?
URI versioning adds the version number directly in the URL path. For example, '/v1/users' and '/v2/users' are two versions. Express routes are set up to handle each version separately.
Click to reveal answer
intermediate
What is a benefit of using header versioning over URI versioning?
Header versioning keeps URLs clean and consistent. Clients specify the version in HTTP headers, so the URL stays the same. This can be better for caching and hides version details from the URL.
Click to reveal answer
beginner
Show a simple Express route example using URI versioning for version 1 and version 2.
const express = require('express');
const app = express();
app.get('/v1/users', (req, res) => {
res.send('Users from API version 1');
});
app.get('/v2/users', (req, res) => {
res.send('Users from API version 2 with new data');
});
app.listen(3000);Click to reveal answer
Which of these is NOT a common API versioning strategy?
✗ Incorrect
Database versioning is unrelated to API versioning strategies. The others are common ways to version APIs.
In URI versioning, where is the version number placed?
✗ Incorrect
URI versioning places the version number directly in the URL path, like '/v1/resource'.
What is a key advantage of header versioning?
✗ Incorrect
Header versioning keeps URLs clean and simple by moving version info to headers.
Which Express method is used to define a route for a specific API version?
✗ Incorrect
app.get() defines a GET route; versioning is handled by the URL or headers, not a special method.
Why is API versioning important when updating an API?
✗ Incorrect
Versioning lets you add features or fix bugs without breaking apps that use older API versions.
Explain the differences between URI versioning, query parameter versioning, and header versioning in APIs.
Think about where the version info is placed and how clients specify it.
You got /4 concepts.
Describe how you would implement API versioning in an Express app using URI versioning.
Focus on route setup and handling different versions.
You got /4 concepts.