Issues

ZF-5027: Zend_Rest isn't really RESTful

Issue Type: Improvement Created: 2008-11-22T10:55:18.000+0000 Last Updated: 2012-11-20T21:38:07.000+0000 Status: Open Fix version(s): Reporter: Toby Boudreaux (tobyjoe) Assignee: None Tags: - Zend_Rest_Client

  • Zend_Rest_Server

Related issues: Attachments:

Description

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.

Comments

Posted by Tomá? Procházka (t.prochazka) on 2008-12-17T01:39:50.000+0000

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.

Posted by Tomá? Procházka (t.prochazka) on 2008-12-17T01:47:33.000+0000

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

<pre class="highlight">
$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()

Posted by Tomá? Procházka (t.prochazka) on 2008-12-17T04:36:11.000+0000

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

Posted by Olivier Riffaud (olivier.riffaud) on 2010-06-14T07:41:53.000+0000

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

<pre class="highlight">
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('<a>php://input</a>'), $vars);
            $this->setParams($vars);
        }
        parent::__construct($uri);
    }
}

And in Zend_Rest_Route, i removed

<pre class="highlight">
unset($params[$this->_actionKey]);

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

<pre class="highlight">
$.put('/myController/format/html', function(data){});

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts