The web middleware is by default loaded for ebery route in the app/Http/routes.php file. If you create an API, you mostly don't need all the things this web middleware is loading, like cookie sessions and CRSF protection. To create routes for the API:
- Create a new app/Http/routes-api.php file and add the routes for the API.
- Copy the mapWebRoutes method to mapApiRoutes in the app/Providers/RouteServiceProvider.php file and adjust it, so it loads the api middleware and requires the routes-api.php file.
- Make sure it calls this new method in the same place it now only calls mapWebRoutes.