PHP Rest Server (part 1 of 3)
Monday, September 1. 2008
Looks good Lorna, I have been doing something fairly similar. I don’t know about you but I found that following the REST pattern wrote a lot of the code itself.
I’m not sure if you did this or not, but I found it beneficial to abstract the request into an interface and then do something like:
$service->handle($request)
Gives you a little extra flexibility.
I’m curious about how you handle responses, looks like you’re doing things a little differently to me, so looking forward to your next post.
Have you seen the article in php|architect on creating a service with the Reflection API?
http://c7y.phparch.com/c/entry/1/art,rest_with_reflection/1
(Seems like a lot of people have had a go at this problem—I’ve written something similar as well. In my case it turned out to be really convenient to pull the method name from the "filename" of the URL, and the output type (JSON, text, debug) from the "extension" part of the URL.)
There’s also:
http://framework.zend.com/manual/en/zend.rest.server.html
Rory: I didn’t abstract the request object but it would be a nice separation to do so.
Michael: I haven’t read that but I will, thanks for the link. Calling formulaic method names seems to a feature of most implementations I’ve seen so far. I haven’t looked at the Zend Framework stuff – the application for this service is high-availability enough to keep us away from frameworks of any kind, purely for performance reasons.
You may also look at
http://wso2.org/projects/wsf/php
The WSO2/WSF project.
Thanks Lorna. Some time ago I wanted to build a service or something to provide data to my application, but I didn’t know where to start. I think your approach and implementation is very valuable and useful. Thanks again!!
rajika: Thanks for pointing us at that resource.
Robert: Thanks for your comment, its great to hear that this is helpful to you – good luck :)
David: see part 2 of the tutorial – http://www.lornajane.net/posts/2008/PHP-Rest-Server-part-2-of-3
Lorna, nice into!
Question, I read all 3 parts, and still not get where do you defined Rest_Service()?
Or I’m blind were :)
Thanks
NC: it isn’t actually very clear (I must update this tutorial some time), the Rest_Service class contains the methods defined in Part 2 … hope that helps!
hi Lorna, really good article, thank you.
I’m looking to implement a rest server in php and it would be very nice if you could explain more about the .htaccess file. I can’t find any simple help about that kind of file.
Thx in advance
hi Lorna,
great post. I’m looking to use php web services and the REST server model for my own windows desktop application which will use the web service to authenticate the user. Will reduce piracy. I like your approach because it’s lean and mean. I’ve been wrtining software for over 20 years now and I totally agree with you that frames are great but for performance it’s best to creatye something lite weight!
Nitin



This is part 2 of my rest service writing article. In part 1 we saw the library which holds the functionality we will be using, and we also handled the incoming request and captured all the data we’ll be using. The REST Service This is not really t
Tracked: Sep 03, 07:38
This is part 3 of my article about writing a restful service server. If you haven’t already, you might like to read part 1 (covering the core library and grabbing the information we need from the incoming request) and part 2 (covering the service handle
Tracked: Sep 05, 12:08