Maintaining Easy Versioning of the ASP.NET Core API While Old Clients Remain Active

Building apps that keep evolving without disrupting current integrations requires careful consideration of API versioning. Request models, response structures, and business rules may be somewhat basic when an ASP.NET Core API is first created. However, the API contract frequently has to be modified when new features are added.

When several clients utilise different versions of the same API, a problem arises. Think about a mobile application with an ASP.NET Core backend. A new version of the application with enhanced business logic, updated answer fields, and more customer data is released by the development team. Not all users, though, update the program right away. For several months, some users could stick on earlier versions.

If the backend changes its existing response structure without considering those clients, older application versions may stop working correctly.

This situation is common in mobile applications, enterprise integrations, and applications where multiple systems consume the same API.

API versioning provides a structured way to introduce changes while maintaining compatibility with existing clients.

In this article, we will explore how to implement API versioning in ASP.NET Core, compare different versioning approaches, maintain support for older clients, and manage API changes without making the application unnecessarily complicated.

Why API Versioning Matters in ASP.NET Core

An API contract defines how clients communicate with a server. It includes endpoint URLs, request parameters, data models, response structures, and expected behavior.

When an API contract changes, existing clients may not understand the updated behavior.

For example, consider the following customer response:

{
  "id": 101,
  "name": "Peter",
  "email": "Peter@example.com"
}

An older mobile application may expect these three properties.

Later, the development team introduces additional customer information:

{
  "id": 101,
  "fullName": "Peter Arthur",
  "emailAddress": "Peter@example.com",
  "status": "Active"
}

This response may be useful for a newer application, but an older client that expects Name and Email may no longer behave correctly.

The problem is not simply adding new properties. Renaming existing properties, changing data types, removing fields, or modifying business behavior can introduce compatibility issues.

API versioning allows developers to maintain separate contracts for different client generations.

Common Reasons for Introducing a New API Version

A new API version may be required when:

  • An existing property needs to be renamed or removed.
  • A request model requires a different structure.
  • A response format changes significantly.
  • Authentication or authorization behavior changes.
  • An endpoint introduces a different business workflow.
  • An existing integration requires a new contract.

Not every API modification requires a new version. Adding an optional response property or introducing a new independent endpoint may be backward-compatible, depending on how clients consume the API.

The goal should be to avoid unnecessary versions while protecting existing integrations.

Understanding API Versioning Approaches

ASP.NET Core applications can expose API versions in different ways.

The most common approaches are URL-based versioning, query-string versioning, and header-based versioning.

URL-Based Versioning

In URL-based versioning, the API version is included directly in the endpoint.

For example:

/api/v1/customers
/api/v2/customers

This approach is easy to understand because the version is visible in the request URL.

It is particularly useful for mobile applications, public APIs, and integrations where developers need to identify the supported API version quickly.

Query-String Versioning

In query-string versioning, the version is passed as a query parameter.

/api/customers?api-version=1.0
/api/customers?api-version=2.0

This approach keeps the endpoint path unchanged while allowing clients to request different versions.

It can be useful when existing applications already use a shared endpoint structure.

Header-Based Versioning

Header-based versioning sends the API version through an HTTP request header.

For example:

GET /api/customers HTTP/1.1
X-Api-Version: 2.0

This approach keeps version information separate from the URL.

It can be suitable for internal APIs and integrations where clients already manage custom request headers.

Comparing API Versioning Approaches

Approach Version Location Advantages Considerations
URL-based Request URL Easy to understand and test Version appears in endpoint paths
Query-string Query parameter Keeps endpoint paths unchanged Requires consistent query handling
Header-based HTTP header Separates version from resource URL Less visible during manual testing

For many ASP.NET Core applications, URL-based versioning is a practical starting point because it makes API versions easy to identify in logs, browser tools, and application code.

Setting Up API Versioning in ASP.NET Core

We will implement URL-based API versioning using the Asp.Versioning.Mvc package.

First, create a Web API project:

dotnet new webapi -n VersionedApi
cd VersionedApi

Install the required NuGet package:

dotnet add package Asp.Versioning.Mvc

This package provides API versioning support for ASP.NET Core controllers.

Configuring API Versioning

Open Program.cs and configure API versioning services:

using Asp.Versioning;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddControllers();

builder.Services
    .AddApiVersioning(options =>
    {
        options.DefaultApiVersion = new ApiVersion(1, 0);

        options.AssumeDefaultVersionWhenUnspecified = false;

        options.ReportApiVersions = true;
    });

var app = builder.Build();

app.MapControllers();

app.Run();

Let’s understand the important settings.

DefaultApiVersion defines the default version used when the application needs a configured default.

AssumeDefaultVersionWhenUnspecified controls whether requests without an explicit version should automatically use that default.

In this example, it is disabled. This makes clients specify their intended version rather than silently receiving an unexpected contract.

ReportApiVersions adds response headers that communicate supported and deprecated API versions where applicable.

For a URL-based implementation, the application must also register URL-segment versioning.

Update the configuration:

builder.Services
    .AddApiVersioning(options =>
    {
        options.DefaultApiVersion = new ApiVersion(1, 0);

        options.AssumeDefaultVersionWhenUnspecified = false;

        options.ReportApiVersions = true;

        options.ApiVersionReader =
            new UrlSegmentApiVersionReader();
    });

The UrlSegmentApiVersionReader tells the versioning system to obtain the API version from the URL.

Creating Multiple API Versions

Once versioning is configured, developers can create separate controller implementations for different versions.

Consider a customer API.

Version 1 returns the original customer response:

using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[ApiVersion(1.0)]
[Route("api/v{version:apiVersion}/customers")]
public class CustomersV1Controller : ControllerBase
{
    [HttpGet("{id}")]
    public IActionResult GetCustomer(int id)
    {
        return Ok(new
        {
            Id = id,
            Name = "PeterArthur", Email = "Peter@example.com" }); } }

The newer application version needs additional customer information and a different response structure.

Create another controller:

using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[ApiVersion(2.0)]
[Route("api/v{version:apiVersion}/customers")]
public class CustomersV2Controller : ControllerBase
{
    [HttpGet("{id}")]
    public IActionResult GetCustomer(int id)
    {
        return Ok(new
        {
            Id = id,
            FullName = "PeterArthur", EmailAddress = "Peter@example.com", Status = "Active" }); } }

Now the API exposes two different contracts:

GET /api/v1/customers/101

GET /api/v2/customers/101

The older mobile application can continue using version 1, while the newer application uses version 2.

Both versions can run within the same ASP.NET Core application.

This approach avoids maintaining two completely separate backend deployments for a relatively small contract change.

Sharing Business Logic Between API Versions

One common mistake when introducing API versioning is duplicating the complete business logic in every controller.

For example, both CustomersV1Controller and CustomersV2Controller may independently retrieve customer information from the database, calculate account status, and apply business rules.

Over time, these implementations can become inconsistent.

A better approach is to keep business logic in a shared service and allow each controller to create its own response model.

Consider the following service:

public class CustomerService
{
    public Customer GetCustomer(int id)
    {
        return new Customer
        {
            Id = id,
            Name = "PeterArthur", Email = "Peter@example.com", Status = "Active" }; } } public class Customer { public int Id { get; set; } public string Name { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; public string Status { get; set; } = string.Empty; }

Register the service:

builder.Services.AddScoped<CustomerService>();

Both controllers can now use the same service while returning different response contracts.

This separates API versioning concerns from business logic.

The database structure does not necessarily need to change whenever an API response changes.

Handling Old Clients Without Breaking Them

Supporting older clients is often more difficult than introducing a new API version.

A mobile application may remain installed even after a newer version becomes available. Some users may not update immediately, while enterprise integrations may require separate release approval.

Developers should avoid assuming that every client will migrate as soon as the backend is deployed.

A practical strategy includes the following steps.

1. Keep Existing Versions Available

When introducing a new API version, do not immediately remove the previous version.

Allow older clients to continue using the existing endpoints while the newer version is adopted.

2. Avoid Changing Existing Contracts Unexpectedly

Do not rename existing response properties, change their data types, or remove fields without evaluating their impact on current clients.

Even seemingly small changes can affect application models and business logic.

3. Introduce New Response Models

Create separate response models when a new API version requires a different structure.

Avoid using one model with many conditional properties based on API version.

Separate models make the contract easier to understand and maintain.

4. Track Client Version Usage

Maintain information about which API versions are actively being used.

Application logs, API gateway analytics, and request metadata can help identify older clients that still depend on previous contracts.

Do not rely only on the API version. When appropriate, record the client application version separately.

5. Communicate Deprecation Clearly

When an older API version is scheduled for retirement, communicate the migration requirements to affected consumers.

A deprecation policy should include a migration path, expected support period, and planned retirement process.

Avoid removing an API version simply because a newer version has been released.

Best Practices for API Versioning in Production

Keep Versioning Simple

Do not create a new API version for every small modification.

Backward-compatible changes generally do not require a new version.

Introduce a new version when the existing contract or behavior needs an incompatible change.

Separate Request and Response Models

Use dedicated request and response models for each API version.

This prevents changes to one version from unexpectedly affecting another.

Share Application Services

Keep database operations and business rules in shared application services wherever the behavior remains the same.

Controllers should primarily handle HTTP concerns and map service results to version-specific contracts.

Test Older API Versions

Include integration tests for all supported versions.

A change to shared business logic should not accidentally modify the behavior expected by an older client.

Document Version Changes

Maintain clear documentation describing changes between versions.

Include updated request models, response structures, authentication requirements, and migration instructions.

Monitor Deprecated Endpoints

Track requests to older versions and identify clients that still depend on them.

This information helps teams decide when an older API version can safely be retired.

Common Mistakes to Avoid

Mistake Impact Recommended Approach
Creating versions for every small change Unnecessary maintenance Version only breaking changes
Removing older endpoints immediately Existing clients stop working Use a planned retirement process
Duplicating business logic Inconsistent application behavior Share application services
Reusing incompatible response models Difficult version maintenance Create version-specific DTOs
Ignoring older client usage Unexpected integration failures Monitor API version traffic
Changing response properties unexpectedly Client deserialization problems Preserve existing contracts
Skipping integration tests Regressions in supported versions Test every active version

Troubleshooting Common API Versioning Problems

API Returns 404 for a Versioned Endpoint

Check whether the controller route contains the correct version segment and whether URL-segment version reading is configured.

For example, verify that the application is using /api/v1/customers rather than an endpoint that does not match its route template.

API Version Is Not Recognized

Verify that the Asp.Versioning.Mvc package is installed and that API versioning services are registered before the application starts.

Also check whether the version format in the request matches the configured API version.

Multiple Controllers Match the Same Request

Check the ApiVersion attributes and route templates.

Each controller should declare the versions it supports, and overlapping routes should be reviewed carefully.

Older Clients Receive Unexpected Responses

Inspect the controller selected for the requested API version.

Also verify that shared services and response mapping logic have not introduced changes that affect the older contract.

Summary

API versioning helps ASP.NET Core applications evolve without unnecessarily breaking existing clients. It is particularly important for mobile applications, enterprise integrations, and systems where different consumers upgrade at different times.

By using Asp.Versioning.Mvc, developers can expose multiple API versions within the same application. URL-based versioning provides a straightforward way to identify supported contracts, while separate controllers and response models help maintain compatibility.

The most important design principle is to keep business logic independent of API versions. Share application services where possible, maintain separate contracts where necessary, and introduce new versions only when breaking changes justify them.

A well-managed versioning strategy also requires monitoring older clients, communicating deprecation plans, and testing every supported version. These practices help teams maintain stable ASP.NET Core APIs while continuing to introduce new features and improvements.

Best and Most Recommended ASP.NET Core 11.0 Hosting

Fortunately, there are a number of dependable and recommended web hosts available that can help you gain control of your website’s performance and improve your ASP.NET Core 11 web ranking. HostForLIFE.eu is highly recommended. In Europe, HostForLIFE.eu is the most popular option for first-time web hosts searching for an affordable plan. Their standard price begins at only €3.49 per month. Customers are permitted to choose quarterly and annual plans based on their preferences. HostForLIFE.eu guarantees “No Hidden Fees” and an industry-leading ’30 Days Cash Back’ policy. Customers who terminate their service within the first thirty days are eligible for a full refund.

By providing reseller hosting accounts, HostForLIFE.eu also gives its consumers the chance to generate income. You can purchase their reseller hosting account, host an unlimited number of websites on it, and even sell some of your hosting space to others. This is one of the most effective methods for making money online. They will take care of all your customers’ hosting needs, so you do not need to fret about hosting-related matters.