I search in the discussions but did not found anything related, please point me if there is already an open conversation.
It would be really nice if there was some thought and code features applied on creating a REST api with a Yii 2.0 application.
Having a REST api is getting a standard for serious web services, and is something that could come with yii 2.0 from core.
I checked what fuelphp does and the below are mostly copycated from there but I think most of it is obvious.
Let's say we have a specific controller like CRestController (sorry bout the Yii 1.1 style naming). The actions in this controller are not prefixed with 'action' but the method that can be accessed like the below example.
<?php class PeopleController extends CRestContoller { public function getList() { $this->render(array( '0'=>array('...'), '1'=>array('...'), )); } public function postPerson() { ... } public function putPerson() { ... } }
I am aware of the
getListwill be confusing and will have issues, so please focus on the idea rather the exact example above.
We could also have the classic action prefix but it would be a nice convention over configuration imho.
In the above example you would notice a "render" function, this is not the classic render but instead give a result in some specific formats like json,xml without having the developer hard times.
If link is like
//Gives json result http://yii/index.php?r=people/list.json //Gives the same result in xml format http://yii/index.php?r=people/list.xml
Let me know what you thing about it or if you have already some ideas.
Friendly and geeky,
Tydeas