Interview frequency: …
Short answer
Use URI Versioning, such as /api/v1/, which is common and clear, or request headers (Header/Accept Versioning) to keep URLs clean.
Explanation
When an API serves mobile apps whose users cannot be forced to update immediately, supporting several versions in parallel becomes necessary. In Laravel, organize versions by separating route groups and controllers into folders (App\Http\Controllers\Api\V1 and V2) and using Route Groups, or use Middleware to inspect the Accept header and route the request internally.
Code example
Route::prefix('v1')->group(base_path('routes/api_v1.php'));
Route::prefix('v2')->group(base_path('routes/api_v2.php'));Common mistakes
- Making breaking changes to the current version without releasing a new version, breaking older mobile app releases.