APIs evolve over time. New business requirements, improved data models, enhanced security, and additional features often require changes to existing endpoints. While these changes improve the API, they can also break applications that depend on older versions.
A production API should support evolution without forcing every client to upgrade immediately. This is where API versioning becomes essential. By introducing versioning, developers can add new functionality, deprecate old behavior, and migrate clients gradually without disrupting existing integrations.
In this article, you'll learn how to implement API versioning in ASP.NET Core 10, compare different versioning strategies, and design APIs that remain backward compatible as they evolve.
Why API Versioning Matters
The Problem with Breaking Changes
Imagine an e-commerce API with the following response:
{
"id": 101,
"name": "Laptop",
"price": 1200
}
Months later, the development team changes the response to:
{
"productId": 101,
"productName": "Laptop",
"price": 1200,
"currency": "USD"
}
Although the new response is more descriptive, existing mobile apps, web applications, and third-party integrations expecting id and name will fail.
API versioning allows both versions to coexist while consumers migrate at their own pace.
Common API Versioning Strategies
URL Versioning
The version is included in the URL.
/api/v1/products
/api/v2/products
Advantages
Easy to understand
Visible in logs
Simple routing
Widely adopted
Considerations
Every new version introduces additional endpoints that must be maintained until older versions are retired.
Query String Versioning
The version is passed as a query parameter.
/api/products?api-version=1.0
Advantages
Existing URLs remain unchanged
Easy for testing
Considerations
Version information is less visible, making documentation and debugging slightly more difficult.
Header Versioning
Clients specify the version using an HTTP header.
api-version: 2.0
Advantages
Clean URLs
Flexible client implementations
Considerations
Headers are less discoverable and require additional configuration in API clients and testing tools.
Configuring API Versioning
Register API versioning during application startup.
builder.Services.AddApiVersioning(options =>
{
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
});
Why This Configuration?
This configuration establishes version 1.0 as the default version while allowing existing clients to continue working even if they don't explicitly specify a version.
Enabling ReportApiVersions adds supported API versions to response headers, helping consumers discover available versions.
Versioning Controllers
A controller can explicitly declare the API version it supports.
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/products")]
[ApiController]
public class ProductsController : ControllerBase
{
}
Why Version Controllers?
Explicit version attributes make supported versions clear while allowing multiple controller implementations to coexist.
Each controller focuses on one API contract, reducing complexity and making future maintenance easier.
Supporting Multiple Versions
An API can expose different implementations simultaneously.
Version 1:
GET /api/v1/products
Version 2:
GET /api/v2/products
Both versions can operate independently, allowing organizations to migrate consumers gradually instead of forcing immediate upgrades.
End-to-End Implementation
Consider an online retail platform.
Architecture:
Web App
│
Mobile App
│
Partner API
│
▼
API Gateway
│
┌───┴──────────────┐
▼ ▼
Version 1 Version 2
│ │
Business Services
│
SQL Database
Migration workflow:
Version 1 remains available for existing clients.
Version 2 introduces additional product information.
New applications adopt Version 2.
Existing consumers continue using Version 1 without interruption.
Usage metrics identify when Version 1 can be safely retired.
After communicating the deprecation timeline, Version 1 is removed.
This approach enables continuous API evolution while minimizing disruption for consumers.
Deprecating Older Versions
Eventually, outdated API versions should be retired.
A recommended migration process includes:

Join the conversation! Your thoughts help the community grow.