Recall & Review
beginner
What is the purpose of API routes in Laravel?
API routes in Laravel define endpoints that respond to HTTP requests, allowing clients to interact with the application programmatically, usually returning data in JSON format.
Click to reveal answer
beginner
Where are API routes defined in a Laravel project?
API routes are defined in the
routes/api.php file, which is separate from web routes and is intended for stateless API endpoints.Click to reveal answer
beginner
How do you define a GET API route in Laravel that returns a list of users?
You use
Route::get('/users', [UserController::class, 'index']); inside routes/api.php. This sets up a GET endpoint at /api/users that calls the index method of UserController.Click to reveal answer
intermediate
What middleware is applied by default to API routes in Laravel?
By default, API routes use the
api middleware group, which includes middleware like throttle:api to limit request rates and bindings for route model binding.Click to reveal answer
intermediate
How can you protect API routes in Laravel to require authentication?
You can add the
auth:sanctum or auth:api middleware to your API routes to require users to be authenticated before accessing them.Click to reveal answer
Where should you define API routes in a Laravel project?
✗ Incorrect
API routes belong in routes/api.php to separate them from web routes and apply API-specific middleware.
Which HTTP method is used to retrieve data from an API route?
✗ Incorrect
GET requests are used to retrieve data without changing anything on the server.
What middleware group is applied by default to Laravel API routes?
✗ Incorrect
The api middleware group is applied by default to routes in routes/api.php.
How do you protect an API route to require user authentication?
✗ Incorrect
Using 'auth:sanctum' middleware ensures only authenticated users can access the route.
What URL prefix do Laravel API routes use by default?
✗ Incorrect
Routes in routes/api.php are automatically prefixed with /api.
Explain how to create a simple API route in Laravel that returns a JSON list of products.
Think about the file location, HTTP method, and response format.
You got /4 concepts.
Describe how middleware helps secure API routes in Laravel.
Consider what happens before your API code runs.
You got /4 concepts.