Web app and API in same Laravel project? Web app and API in same Laravel project? codeigniter codeigniter

Web app and API in same Laravel project?


In my opinion you have 2 choices:

  • Build only the API with Laravel (Response::json everywhere), then build the web app using a JS framework like Angular, or jQuery. Both the web app and the mobile app could make AJAX requests to the Laravel app, and the JS framework would handle displaying it. This would be the "not building the api + web app in the same place" solution. You could have your web app built wherever you want, or inside the Laravel app itself.

    The API would be easy to maintain, and you could even merge the web app and the mobile app, since they would both do the same (unless you actually want them to be different). Also, it's easier to extend, since the interface remains the same across any API consumer app.

    This will help a lot: https://laracasts.com/series/incremental-api-development

  • Building the API and the web app in the same place, would require separating your app in 2: one part would respond to AJAX requests and return JSON and the other part would answer the normal way, returning php views and all that..

    This means a lot of extra work and double the amount of views, since you would have to build the views handled by the the mobile app and the views handled by Laravel itself. That's a lot to cover and maintain (and test).

It depends on what kind of project you're building. Is it a SPA?