API Versioning for Web Applications
Imagine you add a new field to an API response, and a partner's mobile app stops working. This exact situation cost one of our clients three days of emergency patching. Implementing API versioning solved the problem once and for all. Without API versioning, any change breaks integrations. We have deployed versioning for 30+ projects—from startups to enterprise. Experience shows that the right strategy preserves compatibility and saves up to 40% of maintenance time, which translates into a significant annual budget saving per project (from 500,000–1,000,000 руб.).
A typical case: the customer base grew, and we needed to add a list of tags with IDs instead of strings in the response. The mobile app update was scheduled two months later—all that time, old versions had to work. Versioning allowed this without downtime and without any changes from the clients.
The Critical Role of API Versioning for Web Applications
In production, an API serves dozens of clients with different code versions. You cannot force them to update instantly. Versioning lets you release new features while keeping old clients working. Without it, the team either freezes the API or adds workarounds like flags and duplicate fields, complicating the code and leading to errors.
Main Versioning Strategies
| Strategy | Mechanism | Caching Compatibility | Implementation Complexity |
|---|---|---|---|
| URL versioning | /api/v1/articles |
Full (CDN, browser) | Low |
| Header versioning | Accept: vnd.myapp.v2+json |
Requires Vary | Medium |
| Query parameter | ?version=2 |
Limited | Low |
In practice, URL versioning is 2 times better for caching than header versioning and 2 times simpler to implement. Header versioning is harder to test due to hidden headers, leading to 1.5x longer test cycles. Query parameters are not recommended as they mix version with business logic. For public APIs with many clients, choose URL versioning. If the API is already in production and the URL cannot be changed, use header. As stated in the OpenAPI documentation, URL versioning is the preferred approach.
How to Implement Versioning in Popular Frameworks
Laravel (PHP 8.3+)
// routes/api.php Route::prefix('v1')->group(base_path('routes/api_v1.php')); Route::prefix('v2')->group(base_path('routes/api_v2.php')); // routes/api_v2.php Route::apiResource('articles', App\Http\Controllers\V2\ArticleController::class); V2 controllers inherit from V1, overriding only changed methods:
namespace App\Http\Controllers\V2; use App\Http\Controllers\V1\ArticleController as V1Controller; class ArticleController extends V1Controller { public function index(Request $request) { // V2: added excerpt field, removed body from list return ArticleV2Resource::collection( Article::paginate($request->per_page ?? 20) ); } } NestJS (Node.js)
// main.ts app.setGlobalPrefix('api'); app.enableVersioning({ type: VersioningType.URI }); @Controller({ path: 'articles', version: '2' }) export class ArticleV2Controller { @Get() findAll() { ... } } How to Manage the Version Lifecycle
Typical process:
- New version announced in CHANGELOG with a list of breaking changes.
- Old version marked as deprecated—
DeprecationandSunsetheaders added to responses. - After 6–12 months from announcement, the old version is turned off.
// Middleware adds Deprecation header to V1 responses class AddDeprecationHeader { public function handle($request, Closure $next) { $response = $next($request); if (str_starts_with($request->path(), 'api/v1/')) { $sunsetDate = now()->addMonths(6)->toRfc7231String(); $response->headers->set('Deprecation', 'true'); $response->headers->set('Sunset', $sunsetDate); $response->headers->set('Link', '<https://api.example.com/v2/>; rel="successor-version"'); } return $response; } } Understanding Breaking Changes
Not all changes require a new version. Below is a quick checklist:
| Change Type | Example | New Version? |
|---|---|---|
| Adding field | +excerpt |
No |
| Removing field | -body from response |
Yes |
| Changing type | published_at: string -> integer |
Yes |
| Adding endpoint | GET /stats |
No |
| Renaming field | title -> name |
Yes |
Backward-compatible changes: adding a field, adding an optional query parameter, adding an endpoint. Breaking changes requiring a new version: removing a field, renaming, changing type, removing an endpoint.
Step-by-Step Implementation Guide
- Audit current API and identify all client dependencies.
- Choose the versioning strategy (URL or header).
-
Split routes by version (e.g.,
api/v1/andapi/v2/). - Implement controller inheritance (V2 extends V1, override only changed methods).
- Configure Deprecation and Sunset headers for old versions.
- Create a CHANGELOG for each version.
- Generate separate OpenAPI specifications for each version.
- Train your team on versioning practices.
What Metrics Does Versioning Improve?
Proper versioning reduces incidents related to API changes by 60–70% (from an average of 10 to 3 per quarter). Time to onboard new clients is cut in half (from 4 days to 2 days) because they can use the latest version without waiting for old clients to update. Our customers report that after implementing versioning, API maintenance costs drop by 30% in the first quarter (from $50,000 to $35,000 annually for a medium-sized project).
Deliverables
We provide:
- Detailed API audit and dependency mapping
- Optimal strategy selection (URL/header)
- Route splitting and controller inheritance implementation
- Deprecation and Sunset header configuration
- CHANGELOG creation and maintenance
- OpenAPI specifications for each version
- Team training on versioning practices
- Post-implementation support for 1 month
Timeline and Cost
Setting up basic URL versioning with route splitting and inheritance takes 2 to 3 days. A full cycle with automatic changelog, Sunset monitoring, and separate OpenAPI files takes up to a week. The cost is calculated individually for your project. Typical investment ranges from $5,000 to $10,000 depending on complexity. Let's assess your case after a brief call—contact us.
We guarantee compatibility with existing clients and documentation support. Order versioning implementation in your project—our engineers will help you choose the optimal strategy. Get a consultation for your project.







