Three months after we shipped v1 of our payments API, a product manager asked for a seemingly small change: rename amount to total_amount and require a new currency field. Our mobile app needed it, the web team needed it, and the two largest external partners said they could not migrate for at least six months. We had no versioning strategy. What followed was three weeks of feature flags, conditional serialization logic, and a hotfix that broke an integration because we tried to be "backward compatible" without ever defining what that meant. In my experience, that chaos is normal when versioning is treated as a deployment detail instead of an API design decision. The choice between URL path, header, and query parameter versioning is not just cosmetic — it affects caching, routing, client ergonomics, and how painful your eventual deprecation will be.
There is no single correct answer. I have shipped all three approaches in production systems and migrated between them. Each solves the core problem — allowing multiple incompatible representations of the same resource to coexist — but each pushes complexity to a different part of your stack. Understanding those trade-offs early will save you from rewriting middleware, invalidating caches, or fielding support tickets at 2 a.m. when a client suddenly gets a 406 instead of JSON.
Why Versioning Becomes Painful When You Postpone the Decision
Every public API is a contract. Once a consumer writes code against GET /customers/123 and parses { "name": "Jane" }, that shape is locked whether you documented it as stable or not. In my experience, teams that say "we'll version when we need to" end up versioning under pressure, which leads to inconsistent decisions. One endpoint gets a /v2/ prefix, another gets an X-API-Version header, and a third just adds optional fields and hopes nothing breaks.
The second mistake is conflating versioning with backward compatibility. Versioning is the mechanism for isolating breaking changes. Backward compatibility is the discipline of avoiding breaking changes in the first place. If you add a new optional field to a response, you do not need a new version — old clients simply ignore it. If you rename a field, change its type from integer to string, or alter authentication requirements, you need a new version because old clients will fail in unpredictable ways. I try to follow a simple rule: additive, non-breaking changes stay within the same version; anything that requires a consumer to change code to keep working gets a new version.
This distinction directly ties to how you communicate change. I use IETF RFC Standards as a reference for HTTP semantics when designing these contracts, particularly around content negotiation and status codes. For example, sunset and deprecation HTTP headers defined in draft-ietf-httpapi-deprecation-header give you a standard way to signal retirement, regardless of which versioning strategy you choose. Without a consistent versioning scheme, those signals become ad-hoc and easy for clients to miss.
What Actually Constitutes a Breaking Change
Not every change feels breaking to the author but it is to the consumer. Here is the checklist I run through before deciding if a version bump is needed:
Renaming or removing a field, changing a field type, tightening validation (making an optional field required), changing URL structure, changing error format, or altering pagination semantics are breaking. Adding a new endpoint, adding an optional request field, adding a new field to a response, or adding a new enum value that clients are expected to handle gracefully are typically non-breaking — provided you have documented that consumers must ignore unknown fields. That last point is critical. If you do not tell clients to be tolerant, even additive changes will break strict parsers.
The versioning strategy you pick should make this contract explicit. URL and header approaches do it in different places, but the goal is the same: the client declares which contract it expects, and the server honors it or fails loudly.
URL Path Versioning: Making the Version Impossible to Ignore
URL path versioning is the most common approach I see, and for most teams building public REST APIs, it is the pragmatic default. It looks like this: /api/v1/customers vs /api/v2/customers. The version is part of the resource identifier itself.
The primary advantage is visibility. You can see the version in a browser, in curl, in logs, in your CDN cache key, and in your routing layer without inspecting headers. New engineers understand it immediately. When I led the rebuild of a logistics API that served both internal microservices and external partners, we chose path versioning precisely because our support team could diagnose issues from a screenshot of a URL. No need to ask the customer to dump request headers.
It also simplifies routing and deployment. You can route /v1/* and /v2/* to different codebases, containers, or even teams. That isolation is valuable when v1 and v2 have divergent business logic. Most API gateways and reverse proxies match on path out of the box, so you avoid custom header-parsing logic at the edge.
The criticism is that it violates REST principles because the URL should identify the resource, not the representation. I understand that argument, and if you are building a strictly RESTful system as described in REST API Design: Principles That Stand the Test of Time, you might find it inelegant. In practice, though, I have found that purity matters less than operability. The duplication is real — you are effectively publishing a new set of resources — but that duplication is intentional. It makes ownership and deprecation clear.
// Express.js example: explicit path versioning with isolated routers
import express from 'express';
import v1Router from './routes/v1/customers.js';
import v2Router from './routes/v2/customers.js';
const app = express();
// v1 keeps legacy field names, v2 introduces breaking changes
app.use('/api/v1', v1Router);
app.use('/api/v2', v2Router);
// Optional: redirect or reject unversioned requests explicitly
app.use('/api/*', (req, res) => {
res.status(400).json({
error: 'api_version_required',
message: 'Use /api/v1 or /api/v2. See docs at /docs/versioning'
});
});
app.listen(3000);
Where Path Versioning Causes Friction
The main downside is proliferation. If you version the entire API as /v2/ because one resource changed, you either duplicate every unchanged endpoint under the new prefix or you force clients to mix versions (/v1/customers and /v2/orders in the same integration). I've handled both. Duplication is simpler for clients — they upgrade everything at once — but it increases maintenance burden. Mixing is more efficient but confusing; you end up needing a compatibility matrix in your documentation.
I now version at the API level with a single major version prefix and keep all resources under it, even if only one changed. It is more honest about operational reality: you deploy and deprecate an API version as a unit. It also keeps caching straightforward, since the cache key is the full URL. No header variation means fewer Vary header issues and better hit rates on CDNs.
Header-Based Version Negotiation: Keeping URIs Pure at the Expense of Visibility
Header versioning moves the version out of the URL and into an HTTP header, typically a custom header like X-API-Version: 2 or through content negotiation with Accept: application/vnd.myapi.v2+json. The URL stays clean: GET /api/customers/123 always identifies the same resource, but the server returns a different representation depending on the header.
In my experience, this approach fits best for internal APIs or for teams that control both client and server and have strong API gateway discipline. It aligns well with HTTP's own design — MDN Web Docs documents how the Accept header is intended for this kind of negotiation. It also keeps your URI space stable, which matters if you expose resources that are linked or bookmarked.
The cost is operational opacity. I've debugged production issues where a client was sending Accept: application/json without the vendor prefix and getting the default (old) version, and nothing in the access logs revealed why. You need to log headers explicitly, configure your gateway to route on headers, and teach every client library to set the header correctly. For public APIs consumed by hundreds of external developers with varying skill levels, that extra step creates support load.
# Header-based versioning with a custom media type
# Request for v2
curl -H "Accept: application/vnd.acme.v2+json" https://api.acme.com/customers/123
# Node.js middleware to parse the version from Accept header
function versionMiddleware(req, res, next) {
const accept = req.headers['accept'] || '';
const match = accept.match(/application\/vnd\.acme\.v(\d+)\+json/);
// Default to v1 if no version specified - be explicit about this choice
req.apiVersion = match ? parseInt(match[1], 10) : 1;
if (![1, 2].includes(req.apiVersion)) {
return res.status(406).json({
error: 'unsupported_version',
supported: [1, 2]
});
}
next();
}
Content Negotiation vs Custom Headers
If you go the header route, prefer the Accept header with a vendor media type over a custom X-API-Version header. It is standards-aligned and works better with HTTP tooling, but it is also more verbose. A custom header is simpler to implement and read, yet it is technically a non-standard extension. I have used both; for enterprise B2B APIs where clients are comfortable with HTTP details, the vendor Accept type feels more professional. For internal services where you just need a quick version gate, X-API-Version is fine — just document it consistently and validate it strictly. Never silently fall back to a latest version when the header is missing; that turns a client misconfiguration into a subtle breaking change when you release v3.
Query Parameter Versioning: Flexibility That Complicates Caching and Contracts
Query parameter versioning looks like GET /api/customers/123?version=2 or ?api_version=2. It is easy to implement and easy to test in a browser, which is why I often see it in early-stage startups or MVPs where the API is evolving weekly.
In practice, I have found it to be the weakest of the three for anything beyond a prototype. It pollutes the query string semantics — query parameters should filter or paginate a resource, not select its representation. It also creates ambiguity: is /customers?version=2 the same resource as /customers?version=1? Caching layers, browsers, and CDNs treat them as different cache keys, which can be useful, but many default configurations ignore query strings for cache variation unless you explicitly configure them. I once spent a day tracking down why a CDN was serving v1 responses to v2 clients; the cache key was configured to use only the path.
It also feels less intentional. Clients can accidentally omit the parameter and get a default version, which hides bugs until you change that default. And documentation generators like OpenAPI have no native concept of a version-as-query-param, so you end up describing the same operation twice with different parameter requirements.
That said, there is one scenario where I still use it: when you need to support versioning on top of a legacy system where you cannot change gateway routing to inspect paths or headers. Adding a query param is a change that rarely requires infrastructure updates. If you are stuck with a constrained gateway, it can unblock you, but plan to migrate away from it.
Mapping Semantic Versioning to API Contracts Without Breaking Consumers
Semantic versioning — MAJOR.MINOR.PATCH — was built for libraries, but the logic maps well to APIs if you adapt it. I treat the API major version as the only version that appears in the transport (URL, header, or query). Minor and patch versions are internal implementation details that do not require client action because they are backward compatible by definition.
Here is how I apply it: A PATCH bump is a bug fix that does not change the contract at all — for example, correcting a validation message format that was already documented. A MINOR bump is an additive, backward-compatible change — adding a new field, a new optional parameter, or a new endpoint. A MAJOR bump is any breaking change and is the only one that creates a new /v2/ or requires a new header value.
This discipline forces you to be precise. When we added currency to the payments API, we could have shipped it as a minor change by making it optional with a default of USD and documenting that new integrations should send it. That would have avoided a major bump. Instead, we made it required, which is a breaking change, so we needed v2. The lesson was to design for extensibility upfront: make new fields optional, use objects instead of primitives where you anticipate expansion, and never require clients to send unknown fields.
# Nginx routing for major versions while keeping minor/patch transparent
# Clients only see /v1 and /v2, but we can deploy v2.1 internally
upstream api_v1 { server api-v1:3000; }
upstream api_v2 { server api-v2:3000; }
server {
listen 80;
location ~ ^/api/v1/ {
proxy_pass http://api_v1;
proxy_set_header X-API-Minor-Version 4; # internal tracking only
}
location ~ ^/api/v2/ {
proxy_pass http://api_v2;
}
# Reject requests without a major version
location = /api/customers {
return 400 '{"error":"version_required"}';
}
}
Structuring Backward-Compatible Evolution
To stay within a major version as long as possible, I enforce three rules in code review: First, never rename or delete a field without a major bump — instead, add the new field and deprecate the old one. Second, make your serializers tolerant on input and expansive on output: ignore unknown fields on requests, and include both old and new fields on responses during a transition period. Third, version your error schemas too. Changing { "error": "invalid" } to { "errors": [...] } is a breaking change that often gets overlooked.
This approach reduces version churn. One product I worked on ran v1 for 22 months with 14 minor releases and zero breaking changes, because we treated the major version as expensive. When we finally shipped v2, we had a clear migration guide and a long deprecation window, which is where most versioning strategies succeed or fail.
Deprecation Timelines and Request Routing for Multi-Version APIs
Shipping v2 is easy; retiring v1 is hard. In my experience, the technical routing is the simple part — the human coordination is what determines whether a deprecation is smooth. You need a timeline, automated signals, and a way to measure who is still on the old version.
I use a three-phase model. Phase 1: Announce deprecation with a Sunset date and add Deprecation: true and Sunset: Sat, 31 Dec 2025 23:59:59 GMT headers to every v1 response. Also expose the same information in a /status or /versions endpoint. Phase 2: For 30-60 days before sunset, enable brownouts — short, scheduled windows where v1 returns 429 or 503 with a body explaining the sunset. This surfaces hidden dependencies that do not show up in your analytics. Phase 3: Sunset — v1 returns 410 Gone or 404 with a migration link, not a silent redirect to v2.
To make this work, you need to track usage by version at the gateway, not just in application logs. I tag every request with api_version and ship it to our metrics pipeline. That dashboard is what I use to negotiate extensions with large customers — data, not assumptions. If you are building rate limiting or quotas on top of this, keep in mind that version affects those policies as well; I learned a lot about that after reading Rate Limiting Patterns for APIs: Token Bucket, Sliding Window and Beyond and realizing our v1 and v2 limits were not isolated per version, which let a v1 client accidentally starve v2.
For routing, keep versions as isolated deployments when possible. A monolith with if (version === 1) branches throughout the codebase becomes unmaintainable after two versions. I prefer separate routers or services per major version that share common business logic via internal libraries. When traffic for v1 drops below 5%, you can scale its pool down and eventually decommission it without touching v2 code.
| Strategy | Visibility & Debuggability | Caching Behavior | Client Ergonomics | Best Fit |
|---|---|---|---|---|
| URL Path (/v1/) | High — version visible in logs, browser, curl | Simple — distinct URLs are distinct cache keys; no Vary needed | Very easy — no special headers or tooling | Public REST APIs, external partners, CDN-heavy workloads |
| Header (Accept / X-API-Version) | Low — requires header inspection; invisible in basic logs | Complex — requires Vary: Accept; misconfiguration causes cross-version contamination | Harder — clients must set headers correctly on every request | Internal services, strict REST environments, gateway-controlled ecosystems |
| Query Parameter (?version=2) | Medium — visible but mixes with filtering params | Risky — CDNs may ignore query string unless configured; parameter order issues | Easy to test manually, but easy to omit accidentally | Prototypes, legacy gateways where path/header routing is not possible |
If you are still deciding, I would start with URL path versioning unless you have a specific reason not to. It is not the most elegant, but it is the most observable and the easiest to operate at scale. You can always add header negotiation later as an alternative — I have supported both simultaneously by accepting /v2/customers and /customers with Accept: application/vnd.acme.v2+json as aliases to the same handler — but avoid offering three different ways to specify the same version. Consistency in documentation and client libraries matters more than flexibility here.
For a broader perspective on how versioning fits into your overall design decisions, compare your choice with alternatives like GraphQL's evolution model. The trade-offs I discussed in GraphQL vs REST: An Honest Comparison From Production Experience helped our team decide that for resource-oriented, cacheable data, REST with explicit path versioning gave us clearer contracts than a continuously evolving schema, even though we lost some of the flexibility that schema stitching provides.
Frequently Asked Questions
Should I use minor versions like /v1.2 in the URL?
No, in my experience that creates unnecessary coupling. Expose only the major version in the URL or header (e.g., /v1, /v2). Keep minor and patch versions internal. Clients should not need to change their integration for backward-compatible additions. If you put /v1.2 in the URL, you force clients to decide whether they need 1.2 vs 1.3, and you commit to keeping every minor patch addressable forever.
How long should I support an old API version after releasing a new one?
For public APIs, I plan for 6-12 months minimum, with a published Sunset date from day one of the new version. For internal APIs, 2-3 months with brownouts is often enough. The key is to measure actual traffic by version and by consumer, not just set a calendar date. I have extended deprecations twice because a single large customer accounted for 40% of v1 traffic, and cutting them off would have been worse than maintaining the old code a few months longer.
Can I support multiple versioning strategies at once?
Technically yes, but I would not recommend it as a starting point. Supporting both URL and header versioning for the same API doubles your documentation, testing, and gateway configuration. If you must, make one canonical (usually the URL path) and treat the other as an alias that maps to it internally, with the same handlers and validation. Log which mechanism the client used so you can deprecate the alias later if needed.
Is it a breaking change to add a new enum value to a response field?
It depends on your contract. If your documentation says clients must handle unknown enum values gracefully (e.g., by ignoring or logging them), then it is non-breaking. If clients are known to use strict switch statements without a default case, it will break them. I always document enums as extensible and add new values only in minor releases, but I also notify consumers in advance and provide a preview environment where they can test tolerance.