Zend_Controller-Router-Route-Rest.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.controller.router.routes.rest">
  4. <title>Zend_Rest_Route</title>
  5. <para>
  6. The <classname>Zend_Rest</classname> component contains a RESTful route
  7. for <classname>Zend_Controller_Router_Rewrite</classname>. This route
  8. offers a standardized routing scheme that routes requests by translating
  9. the HTTP method and the URI to a module, controller, and action. The
  10. table below provides an overview of how request methods and URI's are
  11. routed.
  12. </para>
  13. <table frame="all">
  14. <title>Zend_Rest_Route Behavior</title>
  15. <tgroup cols='3' align='left' colsep='1' rowsep='1'>
  16. <colspec colname='method' />
  17. <colspec colname='URI' />
  18. <colspec colname='route' />
  19. <thead>
  20. <row>
  21. <entry>Method</entry>
  22. <entry>URI</entry>
  23. <entry>Module_Controller::action</entry>
  24. </row>
  25. </thead>
  26. <tbody>
  27. <row>
  28. <entry>GET</entry>
  29. <entry>/product/ratings/</entry>
  30. <entry>Product_RatingsController::indexAction()</entry>
  31. </row>
  32. <row>
  33. <entry>GET</entry>
  34. <entry>/product/ratings/:id</entry>
  35. <entry>Product_RatingsController::getAction()</entry>
  36. </row>
  37. <row>
  38. <entry>POST</entry>
  39. <entry>/product/ratings</entry>
  40. <entry>Product_RatingsController::postAction()</entry>
  41. </row>
  42. <row>
  43. <entry>PUT</entry>
  44. <entry>/product/ratings/:id</entry>
  45. <entry>Product_RatingsController::putAction()</entry>
  46. </row>
  47. <row>
  48. <entry>DELETE</entry>
  49. <entry>/product/ratings/:id</entry>
  50. <entry>Product_RatingsController::deleteAction()</entry>
  51. </row>
  52. <row>
  53. <entry>POST</entry>
  54. <entry><literallayout>/product/ratings/:id?_method="PUT"</literallayout></entry>
  55. <entry>Product_RatingsController::putAction()</entry>
  56. </row>
  57. <row>
  58. <entry>POST</entry>
  59. <entry><literallayout>/product/ratings/:id?_method="DELETE"</literallayout></entry>
  60. <entry>Product_RatingsController::deleteAction()</entry>
  61. </row>
  62. </tbody>
  63. </tgroup>
  64. </table>
  65. <para>
  66. To enable <classname>Zend_Rest_Route</classname> for an entire
  67. application, construct it with no config params and add it as the
  68. default route on the front controller:
  69. </para>
  70. <programlisting language="php"><![CDATA[
  71. $front = Zend_Controller_Front::getInstance();
  72. $restRoute = new Zend_Rest_Route($front);
  73. $front->getRouter()->addRoute('default', $restRoute);
  74. ]]></programlisting>
  75. <note>
  76. <para>
  77. If <classname>Zend_Rest_Route</classname> cannot match a valid
  78. module, controller, or action, it will return false and the router
  79. will attempt to match using the next route in the router.
  80. </para>
  81. </note>
  82. <para>
  83. To enable <classname>Zend_Rest_Route</classname> for specific modules,
  84. construct it with an array of module names as the 3rd constructor
  85. argument:
  86. </para>
  87. <programlisting language="php"><![CDATA[
  88. $front = Zend_Controller_Front::getInstance();
  89. $restRoute = new Zend_Rest_Route($front, array(), array('product'));
  90. $front->getRouter()->addRoute('rest', $restRoute);
  91. ]]></programlisting>
  92. <para>
  93. To enable <classname>Zend_Rest_Route</classname> for specific
  94. controllers, add an array of controller names as the value of each
  95. module array element.
  96. </para>
  97. <programlisting language="php"><![CDATA[
  98. $front = Zend_Controller_Front::getInstance();
  99. $restRoute = new Zend_Rest_Route($front, array(), array(
  100. 'product' => array('ratings')
  101. ));
  102. $front->getRouter()->addRoute('rest', $restRoute);
  103. ]]></programlisting>
  104. <sect4 id="zend.rest.controller">
  105. <title>Zend_Rest_Controller</title>
  106. <para>
  107. To help guide development of Controllers for use with
  108. <classname>Zend_Rest_Route</classname>, extend your Controllers from
  109. <classname>Zend_Rest_Controller</classname>.
  110. <classname>Zend_Rest_Controller</classname> defines the 5 most-commonly
  111. needed operations for RESTful resources in the form of abstract action
  112. methods.
  113. </para>
  114. <itemizedlist>
  115. <listitem>
  116. <emphasis><methodname>indexAction</methodname></emphasis> -
  117. Should retrieve an index of resources and assign it to view.
  118. </listitem>
  119. <listitem>
  120. <emphasis><methodname>getAction</methodname></emphasis> -
  121. Should retrieve a single resource identified by URI and assign
  122. it to view.
  123. </listitem>
  124. <listitem>
  125. <emphasis><methodname>postAction</methodname></emphasis> -
  126. Should accept a new single resource and persist its state.
  127. </listitem>
  128. <listitem>
  129. <emphasis><methodname>putAction</methodname></emphasis> -
  130. Should accept a single resource identified by URI and persist
  131. its state.
  132. </listitem>
  133. <listitem>
  134. <emphasis><methodname>deleteAction</methodname></emphasis> -
  135. Should delete a single resource identified by URI.
  136. </listitem>
  137. </itemizedlist>
  138. </sect4>
  139. </sect3>
  140. <!--
  141. vim:se ts=4 sw=4 et:
  142. -->