ZF-5027: Zend_Rest isn't really RESTful


The Zend_Rest package seems to be based on a very liberal, and not very literal, idea of representational state transfer (aka, REST).

  1. Currently, the package is not payload-agnostic, requiring XML. In true REST, the payload structure is arbitrary. Standard HTTP payloads (key-value pairs) should be supported if it's going to be called RESTful.

Improvement: factor out the XML generation and decoding to a sub-package or subclass that can be used when desired.

  1. REST requires the use of HTTP verbs (GET, POST, PUT, DELETE, OPTIONS, HEAD) and not tunneled verbs. In the documentation, for 1.6.0, section 40.3.3, developers are instructed to tunnel the name of an application-specific method. This is RPC & SOA, and not ROA, and is very much anti-REST.

Improvement: support all HTTP verbs instead of custom method invocation (which makes it an RPC library, not a REST library). Follow the pattern of other RESTful frameworks/libs, and the O'Reilly RESTful Web Services book, and tunnel only standard HTTP verbs over POST for connectors that don't support all verbs (_method=PUT) but do not allow custom tunneling (method=doSomethingNonHTTPBased).

REST doesn't mean arbitrary XML over HTTP - it's far more specific to HTTP itself. I would absolutely love to see true REST support in ZFW, and am happy to contribute to a rewrite.


Best solution would be create response object like 'Zend_Rest_ServerResponse', where user can set response code, response mime type (like image/png) and data.

For support POST,GET, etc. I use this code:

$base_path = basename(__FILE__);

$path = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'],$base_path)+strlen($base_path)+1);
$path = parse_url($path, PHP_URL_PATH);
$parray = split('/',$path);

$class = array_shift($parray);
$parray[] = $_SERVER['REQUEST_METHOD'];
$method = '';
$method .= strtolower(array_shift($parray));
foreach ($parray as $part) {
    $method .= ucfirst(strtolower($part));

I call script like /rest.php/userprofile/images/galleries

and this script call method: userprofileImagesGalleriesGet() or userprofileImagesGalleriesPost()

I forgot write, that I use $method variable as $_REQUEST['method'] = $method.

I've just done true REST controllers with ZF, by rewriting Zend_Controller_Request_Http like that :

class Olivier_Controller_Request_Http extends Zend_Controller_Request_Http
    public function __construct($uri = null)
        if($this->isPut() || $this->isDelete()){
            parse_str(file_get_contents('php://input'), $vars);

And in Zend_Rest_Route, i removed


But i do PUT and DELETE HTTP request by using a Jquery bypass :

$.put('/myController/format/html', function(data){});