IvenMS
IvenMS

Reputation: 535

Best practices for using Own API for client and server?

I am creating an applicaton in PHP with MVC based framework. I am exposing a web API for the mobile apps.

The same mobile interface is to be created in web application also. So:

For creating the web interface, can I use the API created for mobile app with HTTP request?

OR

Model methods are exposed, so can we use the model instead of calling and connecting with the API in same server?

What is the best practice?

Upvotes: 0

Views: 287

Answers (1)

ManMohan Vyas
ManMohan Vyas

Reputation: 4062

It depends , if it is your internal product, and you are the only user of API, it is better to expose function base API. eg: addUser, deleteUser.

If you want some one else to use the API and create some application (with different logic depending on their own need) give them model based access. As far as I know functional API's are generally created and exposed. Because this kinds of API saves the number of webservice call and hides the logic underneath it.

edit

if you mean calling the webservice internally ... Ideally design should be such that ..their should be a delegate method that consists of core logic, then that core logic function can be called from your api as well as controller. Calling webservice internally will be a unnecessasary performance overhead. Though you can do that in small size application, but is not at all good solution.

If your model layer holds business logic, though It should be Ideally a seperate layer ...then you should consider using model.

Upvotes: 1

Related Questions