-- robert mena <[email protected]> wrote
(on Tuesday, 30 March 2010, 03:33 PM -0430):
> What's the correct way to use Zend_Rest_Server with the MVC (i.e
> Zend_Controller_Action)?
> 
> I've read about the Zend_Rest_Route but should I have my Controller inherit
> Zend_Rest_Controller (or  define the index/put/get/post/deleteAction) and put
> the new Zend_Rest_Server() / handle inside a certain action?

NO!!!!

Zend_Rest_Route/Controller are the first step in _deprecating_
Zend_Rest_Server. If you look carefully at Zend_Rest_Server, it's not at
all RESTful. Zend_Rest_Route/Controller introduce a RESTful paradigm to
developing applications in ZF, using the MVC.

All you need to do is use the Rest route, and have controllers that
either extend the Rest controller or implement the necessary methods.

 * "indexAction" should return lists of resources, and respond only to
   GET requests (this is already enforced by the Rest route)

 * "getAction" should return the requested resource (indicated by the
   "id" request parameter, which is part of the uri: "/foo/32" -> id ==
   32)

 * "postAction" should create a new resource based on the content posted
   to it, and then return a representation of it while simultaneously
   indicating the new resource's canonical location via a Location
   header and 201 response code.

 * "putAction" should update a specific resource as indicated by the
   "id" request parameter (again, part of the URI), and then return a
   representation of the updated item. Typically, it should only respond
   to PUT requests, but the route also supports POST requests with the
   query parameter "_method" set to "put".

 * "deleteAction" should delete the given resource as indicated by the
   "id" request parameter (again, part of the URI), and return a 204
   response code with no content on success. Typically, this request
   should be via an HTTP DELETE, but can also be via a POST request with
   a query parameter "_method" set to "delete".

How you do the representations and submissions is up to you -- it can be
HTML, XML, JSON -- that will simply depend on your application needs.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Reply via email to