سؤال

Lets say I am building some large application ( multi-page app ) using Laravel. And laravel will allow me to make an API and a website on the same application.

Since the website and the API will communicate with the same database, I was wondering if it is better to consume the same API for the website using some javaScript framework like Vue.js.

So this means I will make single entry point to the database for all the clients ( web , mobile..etc ) what ever call this API.

And my plan is to make:

  • ApiControllers ( communicate with the database and return data )
  • WebControllers ( return blade views which will have vue.js components inside to consume the API ). There is no communication with the database in these controllers.

  • What do you suggest?
  • What will you do in this case?
  • Is this a good idea?
هل كانت مفيدة؟

المحلول

This is a general answer, and may or may not apply to your specific use case. Remember to always think about architectural decisions, as there is no "one size fits all."

Typically, I would use the same services to drive all front-ends, because then you only have to maintain one set of these services, instead of multiple services. You are trading off the extra cost of maintaining multiple versions of the services for the extra cost of ensuring your services can support all platforms. You also have to be cautious as you need to develop in a way that is conscious of the fact all your front-ends will be calling the same back-end.

This may mean you should secure certain endpoints so they can only be accessed by a certain front-end (there are many ways to go about it, so if this is a need do some research on the topic), or that you might have to have a more in-depth deprecation plan (if you use a mobile app, users may have old versions). Maintaining multiple similar versions of the same code is a massive PITA.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى softwareengineering.stackexchange
scroll top