Laravel: AJAX request endpoints in routes/api.php or routes/web.php? Laravel: AJAX request endpoints in routes/api.php or routes/web.php? ajax ajax

Laravel: AJAX request endpoints in routes/api.php or 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.