ASP.NET Core Interview Question #245

How would you design API versioning for a public ASP.NET Core API?

Senior ASP.NET Core Real-World Scenarios Senior Advanced

Quick Interview Answer

Version an API when incompatible contract changes must coexist with existing clients. Decide whether versions are expressed in the URL, query string, header, or media type and keep the convention consistent.

Detailed Explanation

Version an API when incompatible contract changes must coexist with existing clients. Decide whether versions are expressed in the URL, query string, header, or media type and keep the convention consistent.

Prefer additive, backward-compatible changes when possible so a new version is not required for every enhancement. Publish a deprecation policy and give clients enough time to migrate before removing an old contract.

Keep DTOs and endpoint contracts version-aware rather than exposing persistence entities directly.

Code Example

// Conceptual URL-versioned endpoints:
[ApiController]
[Route("api/v1/products")]
public class ProductsV1Controller : ControllerBase { }

[ApiController]
[Route("api/v2/products")]
public class ProductsV2Controller : ControllerBase { }