The API Contract Stability Dilemma
As SaaS applications evolve, database structures and API responses change. If you modify response schemas directly, you break existing third-party integrations.
Exposing versioned API endpoints allows you to deploy new features while supporting legacy clients.
API Standard: Version all public APIs. Choose the versioning pattern that matches your caching and integration strategies.
The Three API Versioning Patterns
API architects select from three routing styles:
1. URI Path Versioning
Including the version directly in the request path: https://api.shivamitcs.in/v1/users.
- ◆Pros: Simple to implement, works with standard browser routing, and caches easily.
- ◆Cons: Violates URI identity principles (the resource changes its URL).
2. Custom Header Versioning
Exposing version requirements inside custom HTTP headers: Accept-Version: 2.0.
- ◆Pros: Clean URIs, allows easy default version routing.
- ◆Cons: Hard to test via standard browsers.
3. Accept Header (Media Type) Versioning
Utilizing content negotiation headers: Accept: application/vnd.shivamitcs.v1+json.
| Versioning Style | URL Cache Friendliness | Developer Usability |
|---|---|---|
| URI Path | Excellent (distinct URLs). | Very Easy. |
| Accept Header | Difficult (requires Vary header). | Complex configuration. |
Implementing Accept Header Selection in .NET
// Web API Controller route selection based on media types
config.Routes.MapHttpRoute(
name: "VersionedApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);By establishing a deprecation schedule (e.g. supporting older API versions for 12 months), teams update SaaS platforms without impacting users.