The imminent release of Laravel 11 promises an array of exciting features and enhancements.
Among its highlights are a leaner application skeleton and various improvements including a streamlined application structure, per-second rate limiting, and health routing.
In Laravel 11, by default, the API route file is not readily visible, and defining API routes requires a specific step.
If you aim to define API routes in Laravel 11, you'll need to publish the API route file using the command.
So, let's see how to publish the API route file in laravel 11, laravel 11 API, and laravel 11 to create an API route.
Run the following command to create an api.php file.
php artisan install:api
The install:api
command installs Laravel Sanctum, which provides a robust, yet simple API token authentication guard which can be used to authenticate third-party API consumers, SPAs, or mobile applications.
In addition, the install:api
command creates the routes/api.php
file
user();
})->middleware(Authenticate::using('sanctum'));
The routes in routes/api.php
are stateless and are assigned to the api
middleware group. Additionally, the /api
URI prefix is automatically applied to these routes.
So, you do not need to manually apply it to every route in the file. You may change the prefix by modifying your application's bootstrap/app.php
file
->withRouting(
api: __DIR__.'/../routes/api.php',
apiPrefix: 'api/admin',
// ...
)
You might also like:
- Read Also: Laravel REST API CRUD Tutorial