What are the main strategies for versioning an ASP.NET Core API (URL, query string, header, media type)?
Short answer
URL segment versioning (/api/v1/products) is the most visible and cache-friendly approach. Query string versioning (/api/products?api-version=1.0) keeps URLs stable but is less discoverable.
Advertisement
AModel answer
URL segment versioning (/api/v1/products) is the most visible and cache-friendly approach. Query string versioning (/api/products?api-version=1.0) keeps URLs stable but is less discoverable. Header versioning (a custom header like X-Api-Version) keeps URLs completely clean but is less visible in browsers/docs. Media type versioning (Accept: application/json;v=1.0) follows REST/HATEOAS purism but is the least commonly adopted in practice.
// URL segment (most common)
[Route("api/v{version:apiVersion}/products")]
// Query string
// GET /api/products?api-version=1.0
// Header
// GET /api/products Header: X-Api-Version: 1.0Real-world example
A public-facing API chooses URL segment versioning (/api/v2/orders) specifically because it's the most discoverable and cache-proxy-friendly option for third-party integrators reading documentation.
Likely follow-ups
- Which strategy works best with CDN and reverse-proxy caching?
- How do you combine multiple versioning strategies simultaneously?
Related topics