API Versioning
ELI5 — The Vibe Check
API versioning is how you update your API without breaking everyone's apps. It's like releasing a new phone model — the old one still works, but the new one has better features. You put /v1/ or /v2/ in the URL so clients can upgrade when they're ready.
Real Talk
API versioning is the practice of maintaining multiple versions of an API simultaneously to ensure backward compatibility. Common strategies include URL path versioning (/v1/users), header versioning (Accept: application/vnd.api.v2+json), and query parameter versioning (?version=2). It allows API evolution without breaking existing consumers.
Show Me The Code
// URL path versioning
app.use('/api/v1', v1Router);
app.use('/api/v2', v2Router);
// Header versioning
app.use((req, res, next) => {
req.apiVersion = req.headers['api-version'] || 'v1';
next();
});
When You'll Hear This
"We need to version the API before releasing the breaking change." / "v1 returns an array, v2 returns a paginated object — both still work."
Related Terms
API (Application Programming Interface)
An API is like a menu at a restaurant. The kitchen (server) can do a bunch of things, but you can only order what's on the menu.
Breaking Change
A Breaking Change is a modification to your API or library that will BREAK existing code that uses it.
REST (Representational State Transfer)
REST is a set of rules for how APIs should behave. Think of it as the etiquette guide for servers and clients talking to each other.