Zend_Controller-Router-Route-Rest.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 <acronym>HTTP</acronym> method and the <acronym>URI</acronym>
  10. to a module, controller, and action. The table below provides an overview
  11. of how request methods and <acronym>URI</acronym>'s are 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><acronym>URI</acronym></entry>
  23. <entry>Module_Controller::action</entry>
  24. </row>
  25. </thead>
  26. <tbody>
  27. <row>
  28. <entry>GET</entry>
  29. <entry><filename>/product/ratings/</filename></entry>
  30. <entry><methodname>Product_RatingsController::indexAction()</methodname></entry>
  31. </row>
  32. <row>
  33. <entry>GET</entry>
  34. <entry><filename>/product/ratings/:id</filename></entry>
  35. <entry><methodname>Product_RatingsController::getAction()</methodname></entry>
  36. </row>
  37. <row>
  38. <entry>POST</entry>
  39. <entry><filename>/product/ratings</filename></entry>
  40. <entry><methodname>Product_RatingsController::postAction()</methodname></entry>
  41. </row>
  42. <row>
  43. <entry>PUT</entry>
  44. <entry><filename>/product/ratings/:id</filename></entry>
  45. <entry><methodname>Product_RatingsController::putAction()</methodname></entry>
  46. </row>
  47. <row>
  48. <entry>DELETE</entry>
  49. <entry><filename>/product/ratings/:id</filename></entry>
  50. <entry>
  51. <methodname>Product_RatingsController::deleteAction()</methodname>
  52. </entry>
  53. </row>
  54. <row>
  55. <entry>POST</entry>
  56. <entry><command>/product/ratings/:id?_method="PUT"</command></entry>
  57. <entry><methodname>Product_RatingsController::putAction()</methodname></entry>
  58. </row>
  59. <row>
  60. <entry>POST</entry>
  61. <entry><command>/product/ratings/:id?_method="DELETE"</command></entry>
  62. <entry>
  63. <methodname>Product_RatingsController::deleteAction()</methodname>
  64. </entry>
  65. </row>
  66. </tbody>
  67. </tgroup>
  68. </table>
  69. <para>
  70. To enable <classname>Zend_Rest_Route</classname> for an entire
  71. application, construct it with no config params and add it as the
  72. default route on the front controller:
  73. </para>
  74. <programlisting language="php"><![CDATA[
  75. $front = Zend_Controller_Front::getInstance();
  76. $restRoute = new Zend_Rest_Route($front);
  77. $front->getRouter()->addRoute('default', $restRoute);
  78. ]]></programlisting>
  79. <note>
  80. <para>
  81. If <classname>Zend_Rest_Route</classname> cannot match a valid
  82. module, controller, or action, it will return <constant>FALSE</constant> and the router
  83. will attempt to match using the next route in the router.
  84. </para>
  85. </note>
  86. <para>
  87. To enable <classname>Zend_Rest_Route</classname> for specific modules,
  88. construct it with an array of module names as the 3rd constructor
  89. argument:
  90. </para>
  91. <programlisting language="php"><![CDATA[
  92. $front = Zend_Controller_Front::getInstance();
  93. $restRoute = new Zend_Rest_Route($front, array(), array('product'));
  94. $front->getRouter()->addRoute('rest', $restRoute);
  95. ]]></programlisting>
  96. <para>
  97. To enable <classname>Zend_Rest_Route</classname> for specific
  98. controllers, add an array of controller names as the value of each
  99. module array element.
  100. </para>
  101. <programlisting language="php"><![CDATA[
  102. $front = Zend_Controller_Front::getInstance();
  103. $restRoute = new Zend_Rest_Route($front, array(), array(
  104. 'product' => array('ratings')
  105. ));
  106. $front->getRouter()->addRoute('rest', $restRoute);
  107. ]]></programlisting>
  108. <sect4 id="zend.rest.controller">
  109. <title>Zend_Rest_Controller</title>
  110. <para>
  111. To help guide development of Controllers for use with
  112. <classname>Zend_Rest_Route</classname>, extend your Controllers from
  113. <classname>Zend_Rest_Controller</classname>.
  114. <classname>Zend_Rest_Controller</classname> defines the 5 most-commonly
  115. needed operations for RESTful resources in the form of abstract action
  116. methods.
  117. </para>
  118. <itemizedlist>
  119. <listitem>
  120. <para>
  121. <emphasis><methodname>indexAction()</methodname></emphasis> -
  122. Should retrieve an index of resources and assign it to view.
  123. </para>
  124. </listitem>
  125. <listitem>
  126. <para>
  127. <emphasis><methodname>getAction()</methodname></emphasis> -
  128. Should retrieve a single resource identified by <acronym>URI</acronym>
  129. and assign it to view.
  130. </para>
  131. </listitem>
  132. <listitem>
  133. <para>
  134. <emphasis><methodname>postAction()</methodname></emphasis> -
  135. Should accept a new single resource and persist its state.
  136. </para>
  137. </listitem>
  138. <listitem>
  139. <para>
  140. <emphasis><methodname>putAction()</methodname></emphasis> -
  141. Should accept a single resource idenitifed by <acronym>URI</acronym>
  142. and persist its state.
  143. </para>
  144. </listitem>
  145. <listitem>
  146. <para>
  147. <emphasis><methodname>deleteAction()</methodname></emphasis> -
  148. Should delete a single resource identified by <acronym>URI</acronym>.
  149. </para>
  150. </listitem>
  151. </itemizedlist>
  152. </sect4>
  153. </sect3>
  154. <!--
  155. vim:se ts=4 sw=4 et:
  156. -->