API Versioned Route Support #56041
Replies: 3 comments 1 reply
-
I wouldn't do this via an array. Flag arguments:Route::version('v1', deprecated: true, function () {
// ...
}); MethodsRoute::version('v1', function () {
// ...
})->deprecated();
If not,
will be exactly the same as
Via Subdomain might also be an option
Why not? This can include
|
Beta Was this translation helpful? Give feedback.
-
I'd ditch the v there and addan option to change the format? |
Beta Was this translation helpful? Give feedback.
-
[Edited] New Routing SyntaxAdd a Route::version('v1', function () {
Route::get('users', [V1\UserController::class, 'index']);
});
Route::version('v2', function () {
Route::get('users', [V2\UserController::class, 'index']);
}); Forget about Route Version Detection that is personal preference. Route List Output (php artisan route:list)
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
RFC: API Versioned Route Support
Overview
Currently, Laravel provides robust routing capabilities, but there is no native, first-class support for versioning API routes. Developers often rely on manual solutions, third-party packages, or custom middleware to handle versioning. This RFC proposes to introduce a built-in, elegant way to define and manage versioned API routes in Laravel.
Motivation
Proposed Implementation
New Routing Syntax
Add a
version()
routing method to the router, allowing grouping of routes by API version:This would automatically prefix routes with the version and allow for grouping by version.
Example Resulting Routes
Route Version Detection
Optionally, allow API version to be determined by:
/api/v1/...
)Accept: application/vnd.yourapp.v1+json
)?version=1
)Provide a middleware or configuration option to choose the strategy.
Route Caching
Ensure that versioned routes are compatible with Laravel’s existing route caching system.
Deprecation Support
Allow marking versions as deprecated to aid documentation and sunset planning:
Backward Compatibility
The new versioned routing is opt-in and does not break existing applications. All current routing remains unchanged if the new method is not used.
Drawbacks
Alternatives
Open Questions
php artisan route:list
) display deprecated routes?Unresolved Issues
Conclusion
Adding native API versioned routing to Laravel will provide a standardized, maintainable, and discoverable way for developers to manage multiple API versions, improve developer experience, and reduce reliance on third-party packages or custom code.
Beta Was this translation helpful? Give feedback.
All reactions