Why does an ASP.NET Core Web API need explicit versioning support, and what package provides it?
Short answer
Without explicit versioning, any change to an endpoint's contract risks breaking existing consumers who can't control when they upgrade -- the Asp.Versioning.Mvc (for controllers) and Asp.Versioning.Http (for minimal APIs) NuGet packages add structured support for defining…
Advertisement
AModel answer
Without explicit versioning, any change to an endpoint's contract risks breaking existing consumers who can't control when they upgrade -- the Asp.Versioning.Mvc (for controllers) and Asp.Versioning.Http (for minimal APIs) NuGet packages add structured support for defining, routing to, and documenting multiple concurrently-supported API versions, letting you evolve the API while giving consumers a migration window.
dotnet add package Asp.Versioning.Mvc
builder.Services.AddApiVersioning(options => {
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
});Real-world example
A payments API team adds Asp.Versioning after their first breaking schema change forced an awkward, unversioned migration where every consumer had to update simultaneously overnight -- versioning going forward gives future changes a graceful rollout window.
Likely follow-ups
- What are the different strategies for exposing a version (URL, header, query string)?
- How do you decide when a change is breaking enough to warrant a new version?
Related topics