Create REST Web Service


(Ryanmhubbard) #1

How do you create a REST based web service using YII? I’ve seen the question asked but no answers nor can i find any tutorials anywhere?

ty


(David) #2

Applications written with the Yii Framework will likely have RESTful qualities. The thought behind REST is that a concise and uniform vocabulary is provided to a client. Yii applications typically return HTML messages, in which case the client is a browser. You may be interested in returning other internet media types like JSON or XML for consumption by other applications. Check out the URI management capabilities that Yii offers:

Yii URI Management

A great step toward designing your RESTful application is planning the structure of your requests. The format of your responses will certainly depend on what is consuming the service.

Cheers!


(Jacob Moen) #3

If you’re able to use SOAP, here’s what the Definitive Yii Guide has to say:

http://www.yiiframework.com/doc/guide/topics.webservice

Would be cool to have other options, but it’s better than nothing. ;)


(Jacob Moen) #4

There is a patch at Google code:

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


(David) #5

Thanks for posting that patch, jacmoe. I haven’t tried it yet, but it looks promising. That’s one of those things that would be nice to see in the core.


(Gustavo) #6

I’ve just created an extension to route url’s based on requested method

Its here if interests you


(Serebrov) #7

Gustavo, jacmoe - it seems you interested in Yii+REST. I searched throw forum posts and found that most threads only mention url management (including Gustavo’s extension and recently fixed issue 802).

But as I understand when we receive PUT or DELETE request we have no access to the request parameters using standard methods. PHP does not populates these requests into superglobals as $_GET and $_POST and Yii’s CHttpRequest also deals with GET and POST only.

Am I wrong? Maybe I missing something, but it seems like for most people first part (url management) is enough. How the second part (get request parameters) is usually solved?

I now have CHttpRequest subclass and use file_get_contents(‘php://input’) to get PUT/DELETE parameters and this is discussed only here.

So maybe there is a simpler method to do this?


(Gustavo) #8

You are right

I actually extended the CHttpRequest to fit my needs, pretty much doing what the guy says in the link you posted


(Serebrov) #9

Yes, I am extending CHttpRequest too and use input parsing.

There is one more thing in the link I posted above - Qiang promised to add support for REST to the Yii and now support is added to the url manager, but not to the CHttpRequest.

So I think we should add one more ticket and ask for this. What do you think?


(Gustavo) #10

Yeah, it is a good idea


(Serebrov) #11

Added - issue 2024


(el chief) #12

Do not use SOAP if you can avoid it. It is awful. Do not use XML if you can avoid it. It is awful.


(Zmt98) #13

I am interested in finding tutorials, source code or video on how to create your own RESTful API (Server or Client) using YII.

I want to build a REST API (Server) that delivers JSON for a mobile iPhone application, but I really do not know where to start; or if YII will help me or how.

Has anyone built an API using YII? Where do I start?

Thanks.


(Jon) #14

http://www.yiiframework.com/wiki/175/how-to-create-a-rest-api/