Advertisement
Intermediate ASP.NET Core, API Versioning

How does query string-based API versioning work, and what are its trade-offs compared to URL segment versioning?

Short answer

Query string versioning (?api-version=1.0) is configured via options.ApiVersionReader = new QueryStringApiVersionReader(), keeping the base URL path stable while the version is an optional parameter -- trade-offs include being less visible/discoverable than a URL segment…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Query string versioning (?api-version=1.0) is configured via options.ApiVersionReader = new QueryStringApiVersionReader(), keeping the base URL path stable while the version is an optional parameter -- trade-offs include being less visible/discoverable than a URL segment, potentially interacting awkwardly with caching proxies that don't account for query strings in cache keys, but being simpler to add optionally without restructuring existing unversioned routes.
builder.Services.AddApiVersioning(options => {
    options.ApiVersionReader = new QueryStringApiVersionReader("api-version");
});

// GET /api/products?api-version=2.0
Real-world example
A team retrofitting versioning onto an already-live, unversioned API chooses query string versioning specifically because it can be added without breaking any existing URLs that omit the parameter and fall back to the default version.
Likely follow-ups
  • How does this interact with CDN or reverse-proxy caching that might ignore query strings?
  • Why is URL segment versioning generally considered more RESTful/discoverable?
Related topics