Your first API client ships, then the mobile app ships, then a partner integration ships, and suddenly you can't rename a single field. Versioning is how you keep moving without breaking people.
Here's the setup I use on client Laravel APIs.
1. Version in the URL, not headers
Header-based versioning ( Accept: application/vnd.app.v2+json ) is elegant, but URL versioning ( /api/v1/... ) is easier to debug, cache, log and explain to a partner's developer. I default to the URL.
// bootstrap/app.php (Laravel 11+) -> withRouting ( api : __DIR__ . '/../routes/api.php' , then : function ( ) { Route :: middleware ( 'api' ) -> prefix ( 'api/v2' ) -> group ( base_path ( 'routes/api_v2.php' ) ) ; } , )
Enter fullscreen mode
Exit fullscreen mode
2. Version the contract, not the whole codebase
Don't copy every controller into a V2 folder. Most of the time only the response shape changes.…