0
0
Laravelframework~10 mins

API versioning patterns in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a versioned API route group in Laravel.

Laravel
Route::prefix('api/[1]')->group(function () {
    Route::get('/users', [UserController::class, 'index']);
});
Drag options to blanks, or click blank then click option'
Aapi
Bversion1
Cv1
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'api' as the version prefix instead of 'v1'.
Using resource names like 'users' as the version prefix.
2fill in blank
medium

Complete the code to specify the controller namespace for API version 2 routes.

Laravel
Route::prefix('api/v2')->namespace('[1]')->group(function () {
    Route::get('/products', [ProductController::class, 'index']);
});
Drag options to blanks, or click blank then click option'
AApp\Http\Controllers\API\V2
BApp\Http\Controllers\API\V1
CApp\Http\Controllers\Web
DApp\Http\Controllers
Attempts:
3 left
💡 Hint
Common Mistakes
Using the V1 namespace for V2 routes.
Using the Web namespace instead of API.
3fill in blank
hard

Fix the error in the middleware assignment for API versioning.

Laravel
Route::prefix('api/v1')->middleware('[1]')->group(function () {
    Route::get('/orders', [OrderController::class, 'index']);
});
Drag options to blanks, or click blank then click option'
Aauth:web
Bauth:api
Cguest
Dverified
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'auth:web' which is for web routes.
Using 'guest' which allows unauthenticated access.
4fill in blank
hard

Fill both blanks to create a versioned API route group with middleware and namespace.

Laravel
Route::prefix('api/[1]')->middleware('[2]')->namespace('App\\Http\\Controllers\\API\\[1]')->group(function () {
    Route::get('/items', [ItemController::class, 'index']);
});
Drag options to blanks, or click blank then click option'
Av3
Bauth:api
Cauth:web
Dv2
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching prefix and namespace versions.
Using 'auth:web' middleware for API routes.
5fill in blank
hard

Fill all three blanks to define a versioned API route with prefix, middleware, and controller namespace.

Laravel
Route::prefix('api/[1]')->middleware('[2]')->namespace('App\\Http\\Controllers\\API\\[1]')->group(function () {
    Route::post('/login', [[3]::class, 'authenticate']);
});
Drag options to blanks, or click blank then click option'
Av1
Bauth:api
CAuthController
Dauth:web
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'auth:web' middleware for API routes.
Mismatching prefix and namespace versions.
Using wrong controller name.