Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What are the common ways to version a REST API (URI path, header, query parameter, media type), and what are the practical differences between them?

A REST API can carry its version in the URI path (/v1/orders), in a custom header (API-Version: 2), in a query parameter (?version=2) or in the media type (Accept: application/vnd.example.v2+json). The path is the most visible and easiest to route and cache but versions the whole API; headers and query parameters keep URIs stable but are easy to forget; media types are precise per representation but less familiar. Whichever we pick, new versions should be rare, because most changes can be additive.

Why this question is asked

Sooner or later every API needs a change that would break existing clients, and the version is how a client says which behaviour it expects. Interviewers ask this question because the choice looks cosmetic but affects routing, caching, testing and documentation for years. In this answer, we will recap what a version protects, look at each of the four styles with an example request, compare their practical differences, see why the best version is the one we never ship, and look at how Spring routes versions to different controller methods.

1What a Version Is For

Clients are written against a contract: the URLs, fields, types and errors an API promises. A breaking change, such as renaming a field or making an optional input required, would make existing clients fail. A version lets the server offer the old contract and the new one at the same time, so each client moves when it is ready.

The version has to travel with every request, so the server knows which contract to apply. The four common styles differ only in where it travels, but that location has real consequences.

2The Four Styles in Practice

Here is the same request for version 2 of an order, written in each style.

Text
GET /v2/orders/42 # URI path
GET /orders/42
API-Version: 2 # custom request header
GET /orders/42?version=2 # query parameter
GET /orders/42
Accept: application/vnd.example.order.v2+json # media type (content negotiation)
Comparing the four styles
StyleVisible and easy to testRouting and cachingGranularity
URI path /v1/...yes, in every URLsimple prefix routing, cache by URLwhole API
Custom headerno, easy to forgetgateway must read header, Vary neededper request
Query parameteryescache key must include itper request
Media typeno, less familiarVary: Accept neededper representation
None is wrong; teams pick based on clients, gateways and tooling.

The path style puts the version in the address itself, so anyone can see it in logs, browsers and documentation. Gateways and load balancers can route /v1 and /v2 to different deployments with a simple prefix rule, and caches treat them as different URLs automatically. The price is that the version covers the whole API surface: shipping /v2 tends to mean a second copy of every endpoint, even the ones that did not change.

A custom header or a query parameter keeps the URI of a resource stable across versions, which matches the REST idea that a URI names a thing, not a format. But a header is invisible in a browser address bar and easy to forget in a curl command or a test, and a client that forgets it silently gets the default version. A query parameter is visible but mixes the version with real filters, and caches must include it in the key.

Media type versioning uses content negotiation: the client asks for a specific representation in the Accept header, and the server answers with a matching Content-Type. It is the most precise, because each resource representation can evolve on its own, but many developers find vendor media types unfamiliar, and some tools handle them poorly. Caches need a Vary: Accept response header to keep representations apart.

3The Best Version Is the One We Never Ship

Whatever style we choose, every live version costs code paths, tests, documentation and support. So the real policy is to make most changes backward compatible. Adding an optional field, a new endpoint or a new optional query parameter does not break a client that ignores unknown fields. Only changes such as removing or renaming a field, changing a type or meaning, or adding a required input need a new version.

In practice that means clients must be written to tolerate unknown fields (Jackson can be configured with FAIL_ON_UNKNOWN_PROPERTIES disabled, and Spring Boot already disables it by default), and server teams must check every change against a list of breaking changes before deciding it needs a version at all.

4How Spring Supports Versioning

For years Spring had no dedicated versioning feature, so teams used path prefixes on @RequestMapping or the headers and params attributes of a mapping. Spring Framework 7 adds built-in API versioning: we configure where the version comes from (a header, a query parameter, a path segment or a media type parameter) and put a version attribute on the mapping. Check your exact version for the configuration names.

Java
@Configuration
class VersionConfig implements WebMvcConfigurer {
@Override
public void configureApiVersioning(ApiVersionConfigurer configurer) {
configurer.useRequestHeader("API-Version"); // or a query param, path segment or media type
}
}
@RestController
class OrderController {
@GetMapping(path = "/orders/{id}", version = "1")
OrderV1 v1(@PathVariable long id) { ... } // API-Version: 1
@GetMapping(path = "/orders/{id}", version = "2")
OrderV2 v2(@PathVariable long id) { ... } // API-Version: 2
}

The framework resolves the version from the request, parses it, and picks the matching method, so the version becomes part of request mapping in the same way as the path or HTTP method.

5Follow-up questions

How would you route two versions of the same endpoint to different controller methods?

On Spring Framework 7 we use the version attribute on @GetMapping or @RequestMapping after configuring the version source, as above. On older versions we use the mapping's own conditions: headers = "API-Version=2" for a header, params = "version=2" for a query parameter, produces with the vendor media type for media type versioning, or different path prefixes. Both methods then call the same service and map the result to their own response DTO, so only the representation is duplicated.

Which style would you choose for a new public API?

Usually the URI path, because partners find it easy to see, test and route, and gateways handle it with no custom rules. For internal APIs with careful clients, a header keeps URIs stable and works well with the Spring Framework 7 support. The more important decision is to version rarely.

Does versioning in the path break REST principles?

Strictly speaking, a URI should identify a resource, and /v1/orders/42 and /v2/orders/42 are the same order, so purists prefer media types. In practice the path style is widely used because its operational benefits are large, and REST is a set of constraints to weigh, not a rule book.

6Conclusion

In this answer, we saw that the version can travel in the path, a header, a query parameter or the media type. The path is visible and easy to route and cache but versions everything; headers and query parameters keep URIs stable but are easy to forget; media types are precise but less familiar. We also saw that the strongest policy is to avoid new versions by making changes additive, and that Spring Framework 7 now supports versioned mappings directly.

What to say in the interviewAbout 70 seconds aloud

Open with

There are four common places to put the version. The URI path, like /v1/orders, is the most visible: it shows up in logs and docs, gateways can route it with a prefix rule, and caches separate versions automatically, but it tends to version the whole API surface at once.

Then, if they want more

A custom header such as API-Version or a query parameter keeps the resource URI stable, but a header is invisible in a browser and easy to forget, so a client may silently get the default, and caches need Vary or the parameter in the key.

Media type versioning, like Accept application/vnd.example.v2+json, is the most precise because each representation evolves on its own, but it is less familiar to developers and tools.

Whichever style we pick, I would keep new versions rare: adding optional fields or endpoints is backward compatible as long as clients ignore unknown fields, so a new version is only for real breaking changes.

In Spring, older versions use path prefixes or the headers condition on a mapping, and Spring Framework 7 adds built-in versioning with a version attribute on the mapping annotations.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 7
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What are the common ways to version a REST API (URI path, header, query parameter, media...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/9eab53ae03/