cameronasmith's avatar

Use router file api.php or web.php

I'm building a SPA that will be doing a lot of AJAX calls from the front-end. These routes are not meant to be used outside of the application. I'm I right in thinking that this should be placed in the web.php file instead of the API file?

Is the API file really only for open calls to your backend?

Cheers,

Cameron.

0 likes
1 reply
jekinney's avatar

Absolutely not. Though you can put routes wherever you want, but API routes are intended for API routes (ajax, sever to server)

The only difference is the default middlewares attached to the route files. Web goes through web, API through API.

Look in the kernel.php in the Most ddleware folder.

Cors headers and/or token based auth is NOT implemented by default, you need to build or get plugins. (Jwt and cors for Laravel). If your spa is hosted on another domain you have to implement cors header middleware or you'll be looking at a lot of errors and no data.

Please or to participate in this conversation.