Zend_Rest_Route
The Zend_Rest component contains a RESTful route
for Zend_Controller_Router_Rewrite. This route
offers a standardized routing scheme that routes requests by translating
the HTTP method and the URI
to a module, controller, and action. The table below provides an overview
of how request methods and URI's are routed.
Zend_Rest_Route Behavior
Method
URI
Module_Controller::action
GET
/product/ratings/
Product_RatingsController::indexAction()
GET
/product/ratings/:id
Product_RatingsController::getAction()
POST
/product/ratings
Product_RatingsController::postAction()
PUT
/product/ratings/:id
Product_RatingsController::putAction()
DELETE
/product/ratings/:id
Product_RatingsController::deleteAction()
POST
/product/ratings/:id?_method="PUT"
Product_RatingsController::putAction()
POST
/product/ratings/:id?_method="DELETE"
Product_RatingsController::deleteAction()
To enable Zend_Rest_Route for an entire
application, construct it with no config params and add it as the
default route on the front controller:
getRouter()->addRoute('default', $restRoute);
]]>
If Zend_Rest_Route cannot match a valid
module, controller, or action, it will return false and the router
will attempt to match using the next route in the router.
To enable Zend_Rest_Route for specific modules,
construct it with an array of module names as the 3rd constructor
argument:
getRouter()->addRoute('rest', $restRoute);
]]>
To enable Zend_Rest_Route for specific
controllers, add an array of controller names as the value of each
module array element.
array('ratings')
));
$front->getRouter()->addRoute('rest', $restRoute);
]]>
Zend_Rest_Controller
To help guide development of Controllers for use with
Zend_Rest_Route, extend your Controllers from
Zend_Rest_Controller.
Zend_Rest_Controller defines the 5 most-commonly
needed operations for RESTful resources in the form of abstract action
methods.
indexAction() -
Should retrieve an index of resources and assign it to view.
getAction() -
Should retrieve a single resource identified by URI
and assign it to view.
postAction() -
Should accept a new single resource and persist its state.
putAction() -
Should accept a single resource idenitifed by URI
and persist its state.
deleteAction() -
Should delete a single resource identified by URI.