HowTo: Build an RESTful API with Yii

is what I’am searching for.

Is it currently possible to create an rest API with Yii?

If yes, is there any documentation?

Thanks!

I’am also looking for a rest api. The only thing I found is this:

http://code.google.com/p/yii/issues/detail?id=802&q=rest

I will try it out the next days.

Same here - looking for a REST Api for yii to use instead of the built-in SOAP one

Here is a good web services framework that can compliment your yii app - http://wso2.com/products/web-services-framework/php/

+1!

REST is relatively easy.

Once you know how.

Fortunately, there are people out there who have written some good articles on the subject:

http://www.gen-x-design.com/archives/create-a-rest-api-with-php/

And:

http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/

The latter even got two repos on Github. :)

Made for CodeIgniter, but it is simple and similar enough, so that could be ported to our Yii apps easily.

I am going to go that route.

Maybe with the help of this patch:

http://code.google.com/p/yii/issues/detail?id=802

SOAP is more powerful, of course.

But a simple REST implementation shouldn’t be too hard.

Would be awesome to have the functionality in the Yii framework, but … :)

I dug a bit deeper into this and discovered that the Pogostick Yii Extensions has REST ‘stuff’ in it:

https://github.com/lucifurious/ps-yii-extensions

Have any of you succesfully used that to make your app serve rest requests? :)

I had a look at the patch enabling the REST API.

The example provided is as followed:




'rules'=>array(

    'articles' => array('articles/index', 'httpMethod' => 'GET'),

    'articles/<id:\d+>' => array('articles/show', 'httpMethod' => 'GET'),

    'articles' => array('articles/create', 'httpMethod' => 'POST'), 

    'articles/<id:\d+>' => array('articles/update', 'httpMethod' => 'PUT'),

    'articles/<id:\d+>' => array('articles/update', 'httpMethod' => 'POST'),

    'articles' => array('articles/delete', 'httpMethod' => 'DELETE'),  

)



Correct me if I’m wrong but it looks like the above array of rules will become the following:




'rules'=>array(

    'articles/<id:\d+>' => array('articles/update', 'httpMethod' => 'POST'),

    'articles' => array('articles/delete', 'httpMethod' => 'DELETE'),  

)



as same array indexes are used multiple time, only the last would remain?

Therefore, once the article update using PUT or POST method will be declared, the article show using the GET method won’t be recognised?

Has anyone used it that way?

Cheers

+1

Mini-howto here:

http://www.yiiframework.com/forum/index.php?/topic/14172-api-application-programming-interface/