I’m about to design a Zend web application which, in order to render its views, will use data which should also be retrievable through a JSON-RPC api, for mobile native apps. I was wondering how to structure the project to keep these two parts independent. The web application is meant to be launched by going to the following URL:
Then, the iOS and Android client should be able to use the JSON-RPC api by sending post requests to
http://www.domainname.com/api/
Should the web application and the api be two separate zend applications or not? I’m skeptical about this because, as the data they will manage is substantially the same, the request handler classes and the controllers for the webapp will have a bunch of similar code to retrieve and manipulate the data to be returned.
Is there a good, clean and flexible way to use the same “back end” code for both the JSON-RPC server and the web app?
I would like to avoid code duplication but also make the api calls as fast as possible.
Thanks to anyone who will help!
You can actually achieve this quite easily.
When the controller handles it, use…
If you are saving data, the procedure can be the same. Usually, you would just use that to return a view or JSON. For example…
I hope that helps and makes sense!