So, I am going to develop this web application using the Yii framework. My app also needs to expose a REST apis for most of it’s functionality.
Essentially, my controllers will be performing CRUD operations on more than one model. The business logic will be non-trivial. I expect the controller to get complex at times.
My question is how should I go about implementing this app? I can think of 3 ways to develop this app.
-
I develop a regular yii webapp where the app-controller has most of the logic - it talks to models, does it’s “thing” and calls the views to render the “things”. Then I have a separate api-controller which contains the same kind of business logic - it talks to models, does its “thing” and then returns these “things” in the form of xml or json back to clients. The con of doing it this way is code duplication - two different controllers having essentially, the same business logic.
-
I develop a REST api using the YII framework first and then have another webapp which talks to this REST api and renders the UI in the browser. This way there will be no code duplication. The downside of doing it this way is, possibly, performance - there would be some model->json->html which could have otherwise been avoided for the webapp.
-
Third, and possibly the most desirable way, would be to treat the JSON and XML as "views" in the MVC. Keep the same controller and depending on where the calls are coming from I spit out HTML or JSON.
Can anyone comment on what is the standard way (if any) of implementing what I want to do. I do not know enough about YII to know if (3) can be accomplished.
Also, if anyone has pointers to developing a REST API using YII framework, please let me know. I have already seen http://www.yiiframework.com/wiki/175/how-to-create-a-rest-api but I can’t find anything else.
PS: As you might have guessed, I’m a yii beginner.
Thanks
Manish