ApiVersionReader.Combine(reader1, reader2, ...) lets you accept a version from multiple sources simultaneously, checking each in order until one provides a value -- useful for supporting legacy clients using one convention (like a header) while newer clients migrate to a preferred convention (like URL segments), though care must be taken to define clear precedence if a request somehow specifies conflicting versions via different readers.
builder.Services.AddApiVersioning(options => {
options.ApiVersionReader = ApiVersionReader.Combine(
new UrlSegmentApiVersionReader(),
new HeaderApiVersionReader("X-Api-Version")
);
});
// Accepts either /api/v2/products OR /api/products with X-Api-Version: 2.0 header
Real-world example
An API supporting both a legacy internal tool (using an X-Api-Version header convention established years ago) and new public consumers (expecting modern URL-segment versioning) accepts both simultaneously during a gradual internal migration period.
Likely follow-ups
What happens if a request specifies conflicting versions via two different readers?
When would you want to restrict this back to a single reader for clarity?
RESTful Web APIs & ControllersConfiguration & Options Pattern
gRPC doesn't use ASP.NET Core's HTTP-based API versioning middleware at all -- instead, versioning is expressed through protobuf's own convention of additive, backward-compatible field changes for minor evolution, and for breaking changes, defining an entirely new service (like OrderServiceV2) or placing it in a versioned package/namespace within the .proto file itself, since the service name and package are part of the gRPC method's fully-qualified routing path.
// order_v1.proto
package myapp.orders.v1;
service OrderService { rpc GetOrder(GetOrderRequest) returns (OrderResponse); }
// order_v2.proto -- breaking change, new package and service
package myapp.orders.v2;
service OrderService { rpc GetOrder(GetOrderRequestV2) returns (OrderResponseV2); }
Real-world example
A gRPC-based internal platform evolves its OrderService contract additively (new optional fields) for two years without any versioning scheme needed at all, only introducing a v2 package when a genuinely incompatible restructuring became unavoidable.
Likely follow-ups
How does protobuf's field numbering support additive evolution without versioning?
When is a new gRPC service package truly necessary versus additive changes being sufficient?
A regression test suite organized by version (parameterized integration tests running the same test scenarios against each supported version's endpoint, using WebApplicationFactory with version headers/URLs varied per test case) ensures that ongoing development on newer versions doesn't accidentally break older, still-supported versions -- critical since deprecated doesn't mean 'can silently break', only 'scheduled for eventual removal', and consumers still relying on it deserve continued correctness guarantees until the announced removal date.
[Theory]
[InlineData("1.0")]
[InlineData("2.0")]
public async Task GetProduct_ReturnsCorrectShape_ForVersion(string version) {
var client = _factory.CreateClient();
var response = await client.GetAsync($"/api/v{version}/products/1");
response.EnsureSuccessStatusCode();
// assert version-appropriate response shape
}
Real-world example
A CI pipeline runs the full regression suite against both v1 (deprecated but still supported) and v2 (actively developed) on every pull request, catching a case where a v2-focused refactor accidentally introduced a shared-code regression that broke v1's still-supported behavior.
Likely follow-ups
How do you avoid excessive test duplication across many supported versions?
At what point does a deprecated version get removed from the regression suite too?
Testing ASP.NET Core ApplicationsCI/CDPublishing & Deployment
Setting options.ReportApiVersions = true causes the versioning middleware to automatically add api-supported-versions (listing every currently active version) and, if applicable, api-deprecated-versions headers to every API response, giving clients and monitoring tools visibility into the full version landscape without needing separate documentation lookups.
builder.Services.AddApiVersioning(options => {
options.ReportApiVersions = true;
});
// Every response now includes, e.g.:
// api-supported-versions: 1.0, 2.0, 3.0
Real-world example
An API gateway's monitoring dashboard automatically tracks which API versions are still actively in use by parsing the api-supported-versions header from live traffic, informing decisions about when it's finally safe to remove an old version.
Likely follow-ups
Does this header appear on every response or only versioned endpoints?
How would client-side tooling consume this header automatically?
While Asp.Versioning itself doesn't have a built-in 'sunset date' concept, you can add a custom Sunset HTTP header (following the IETF Sunset header draft/RFC 8594 convention) via middleware or an action filter applied to deprecated version endpoints, giving clients a specific, parseable date after which the version will stop working, complementing the deprecated-versions header with concrete timing.
app.Use(async (context, next) => {
await next();
if (context.Request.Path.Value.Contains("/v1/")) {
context.Response.Headers["Sunset"] = "Sat, 31 Dec 2026 23:59:59 GMT";
}
});
Real-world example
A partner API adds a Sunset header with a concrete removal date to every v1 response, giving integrators an unambiguous, machine-parseable deadline rather than a vague 'deprecated, remove eventually' signal.
Likely follow-ups
How does the Sunset header relate to the Deprecation header from the same IETF draft?
How would automated client tooling react to an approaching Sunset date?