Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zaster's avatar

API - Correct me if i am wrong

As what i understand , when we deal with api related routes, only the required routes will be under routes/api.php

Ordinary routes can be inside routes/web.php

In that case, in most of the web applications routes/web.php will have many routes than routes/api.php

0 likes
1 reply
frankincredible's avatar
Level 14

From the documentation:

The web.php file contains routes that the RouteServiceProvider places in the web middleware group, which provides session state, CSRF protection, and cookie encryption. If your application does not offer a stateless, RESTful API, all of your routes will most likely be defined in the web.php file.

The api.php file contains routes that the RouteServiceProvider places in the api middleware group, which provides rate limiting. These routes are intended to be stateless, so requests entering the application through these routes are intended to be authenticated via tokens and will not have access to session state.

In other terms: Think of web.php for loading blade views and api.php routes for returning json.

Please or to participate in this conversation.