I have a Laravel app where I fetch and update data asynchronously from my frontend. My question is: Do the endpoints for the AJAX requests go into the routes/api.php
or in the routes/web.php
?
Normally in web.php
as the routes will use the 'web' middleware to access the session and other web-related middleware (CSRF ecc..)
api.php
is dedicated to 'stateless' API calls, where you don't want to use session but instead use stateless specific functions such as api authentication throttle and so on
The routes/web.php
file defines routes that are for your web interface. These routes are assigned the web
middleware group, which provides features like session state
and CSRF protection
. So generally your all routes having web
middleware goes to routes/web.php
.
If your route having api
middleware then it will goes to routes/api.php
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With