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

crushedcoder's avatar

Difference between the API and WEB controllers

I would like to know what is difference between API and web controller except namespace ...Since in both code work as similar ? Is there any performance difference ..Why should i use API controller?

0 likes
1 reply
ftiersch's avatar

Check out the RouteServiceProvider class and the Kernel class. You can define your own "route files" with an own namespace and own middlewares.

The controllers work the same but (by default) the API controllers don't have a session middleware activated for example. They are used for RESTful API requests. But you can change that all how you like.

It's not about the controllers though, only about the things around it (middlewares, authentication etc)

1 like

Please or to participate in this conversation.