There seem to be a variety of PHP frameworks that claim RESTful design patterns.
I’m looking for a framework that does a very good job providing a solid solution to these three items (or their equivalence).
1. Resource Requests
The first thing to do is be able to handle URL to resource resolution.
/path/to/resource = controller.action()
2. Request Methods
The second thing is to handle different types of request methods.
GET /path/to/resource = controller.get()
POST /path/to/resource = controller.post()
Perhaps with a fallback to a universal handler if no request method matches.
GET /path/to/resource = controller.action()
PUT /path/to/resource = controller.action()
POST /path/to/resource = controller.action()
3. Response Formats
Last, I have seen people attach formats to the end of URL’s to help the framework know what type of response is expected.
/path/to/resource.html
/path/to/resource.json
Other ways people pass the response format in the header or as a URI param (?format=json).
These are three items that have to be covered. However, they don’t have to be handled the same way I just showed – those are just examples.
I have been researching for a similar framework, but there doesn’t seem to be much going on in the PHP world. Here is a related question about PHP REST frameworks.
Recess looks interesting, and I found the new REST controllers and routers of the Zend Framework pretty useful. I also started implementing an easier approach on top of the Zend components. Basically you register a bunch of view renderers (HTML, JSON and a simple form of XML are supported out of the box, via accept header parsing or overwriting it with a format=? parameter) and body parsers (Web Foms, and JSON are enabled) and based on this interface:
Where each method returns a plain array or object (with a toArray method) you can create a RESTful resource.
The advantage is, that your resources are entirely decoupled from any Representation.
They don’t even have to know that they are being used via HTTP as long as they follow
the interface.
It is still very alpha, and there didn’t seem to be much interest in it, but it does work so maybe you want to give it a try.