Code review at scale is broken. Here’s how Augment Code is fixing it.

Laravel API Route

Last updated on by

Laravel API Route image

Versioning your API is a vital part of API development, but how do you handle deprecated, sunset (end-of-life), or beta/preview versions? Laravel API Route is a package created by Jean-Marc Strauven that provides complete API versioning lifecycle management for Laravel.

Features

  • Multi-strategy versioning: URI path, Header, Query parameter, or Accept header
  • Automatic deprecation headers: RFC 8594 (Deprecation) and RFC 7231 (Sunset) compliant
  • Version lifecycle management: Active, Deprecated, Sunset, Removed states
  • Intelligent fallback: Route fallback to previous versions when needed
  • Artisan commands: Scaffold, monitor, and manage API versions
  • Usage tracking: Optional analytics per API version
  • Zero configuration start: Works out of the box with sensible defaults

URI path versioning (e.g. /v1/, /v2/) is the default strategy and is often the most popular because it's easy to understand and simple to implement.

To mark a new version of your API as the current stable version, you can use the current() method on the ApiRoute facade in your routes/api.php file:

use Grazulex\ApiRoute\Facades\ApiRoute;
 
ApiRoute::version('v2', function () {
Route::apiResource('orders', App\Http\Controllers\Api\V2\OrderController::class);
})->current();

And to mark previous versions of your API as deprecated and set a planned sunset (end-of-life) date, you can use the deprecated() and sunset() methods:

use Grazulex\ApiRoute\Facades\ApiRoute;
 
ApiRoute::version('v1', function () {
Route::apiResource('orders', App\Http\Controllers\Api\V1\OrderController::class);
})
->deprecated('2025-08-01')
->sunset('2025-12-31');

Which will result in the following automatic headers being included in the response for the deprecated version:

HTTP/1.1 200 OK
X-API-Version: v1
X-API-Version-Status: deprecated
Deprecation: Fri, 01 Aug 2025 00:00:00 GMT
Sunset: Wed, 31 Dec 2025 00:00:00 GMT

If you happen to want to use a different strategy other than URI Path versioning, you can adjust the configuration of this package in config/apiroute.php and utilize query parameters, a header or an accept header in your API requests instead, which will look like the following:

GET /api/orders
X-API-Version: 2
GET /api/orders?api_version=2
GET /api/orders
Accept: application/vnd.api.v2+json

Lastly, there are a few Artisan commands that are available, and these can allow you to quickly view the status of your API versions and even view usage statistics:

php artisan api:status
 
php artisan api:stats --period=30
Screenshot of output of the  api:status artisan command
Output of the `api:status` Artisan command
Screenshot of output of the  api:stats artisan command
Output of the `api:stats` Artisan command

There is a lot more to this package, find out more, read the full documentation and view the source code on GitHub.

Yannick Lyn Fatt photo

Staff Writer at Laravel News and Full stack web developer.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Bacancy

Outsource a dedicated Laravel developer for $3,200/month. With over a decade of experience in Laravel development, we deliver fast, high-quality, and cost-effective solutions at affordable rates.

Visit Bacancy
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
FluentVox: AI Text-to-Speech for Laravel with Voice Cloning and GPU Acceleration image

FluentVox: AI Text-to-Speech for Laravel with Voice Cloning and GPU Acceleration

Read article
Laravel Boost v1.8.10 Released With New AI Prompts and Livewire v4 Support image

Laravel Boost v1.8.10 Released With New AI Prompts and Livewire v4 Support

Read article
Statamic 6 Beta Now Available image

Statamic 6 Beta Now Available

Read article
Everything new in Livewire 4 image

Everything new in Livewire 4

Read article
Cache Without Overlapping in Laravel 12.47.0 image

Cache Without Overlapping in Laravel 12.47.0

Read article
Going Real-Time with Reverb - Laravel In Practice EP17 image

Going Real-Time with Reverb - Laravel In Practice EP17

Read article