1

I wish to know if in the development of an application, the API developed can used by both the client app and the mobile app? For example, having an API that manges products in Symfony 2. A client app is developed in AngularJs to make the web app complete.

I concern is, is it a best practice to use this same API for the mobile app or to create another set of APIs strictly for the mobile App?

The Oracle
  • 2,373
  • 3
  • 26
  • 44

3 Answers3

2

Yes and actually that's one of the main reason we make REST APIs... So you don't have to build multiple server backend logic per client applications you make.

I don't know for React.js but Angular does handle it very well :)

Have a look at $http and $resource

https://docs.angularjs.org/api/ng/service/$http#patch

Hyukchan Kwon
  • 382
  • 1
  • 5
  • 20
2

tl;dr; - Yes, you should, but consider drawbacks!


In ideal, you sure can and you should utilise the same REST API for all your clients. This will result in more maintainable system. Angular.js also has a special factory/service called resource that will do all the heavy lifting for you.

However, we don't live in an ideal world and you would face some "side effects". For example, several years ago Twitter decided to do exactly this and their website used to load javascript and then only query the REST API for tweets. This led to perception of "slow" page rendering. Twitter dropped the idea.

So, the quick answer is "Yes, you should", but the real world answer is "Consider advantages and drawbacks, only then, make your own decision".

Uzbekjon
  • 11,655
  • 3
  • 37
  • 54
  • I need further assistance. On enterprise scale what can be some of the immediate actions that i can take to optimize responses? more still does the advantages far out number the disadvantages? Thanks – The Oracle May 02 '16 at 14:03
  • I will direct my research more on how to optimize REST APIs. Will not mind if you provide me with some real world tips. Thanks. – The Oracle May 02 '16 at 14:11
  • 1
    If your business model doesn't care about SEO, web page render times, and will work more efficiently if split into several teams (core api, web app, etc.), then you may consider taking this road. But, in general it is suggested. As a workaround, many organisations do use one rest api, but do it on server-side. It's the best of 2 worlds. – Uzbekjon May 02 '16 at 14:13
  • Hosting it on cloud would it hurt? – The Oracle May 02 '16 at 14:17
  • There are so many variables. It all depends. It's best if you do some googling. With cloud services there is usually some network overhead since you don't control the physical network. But, some cloud hosting providers give guarantees that services will respond under `n` milliseconds. So, you need to take into account all these factors before deciding on it. But, as a rule of thumb, yeap, go for cloud :) – Uzbekjon May 02 '16 at 14:26
  • Sure thing! Good luck with the project and let us know what you went with. – Uzbekjon May 02 '16 at 14:33
1

Yes, AngularJS supports PATCH.Look at the documentation over here.

With ReactJS, it depends which library you are using. But, React is just a really small library, so you are totally free to use plain JavaScript to make PATCH work. See here.

Community
  • 1
  • 1
ohboy21
  • 4,259
  • 8
  • 38
  • 66