Zend_Rest_Server.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.rest.server">
  4. <title>Zend_Rest_Server</title>
  5. <sect2 id="zend.rest.server.introduction">
  6. <title>Introduction</title>
  7. <para>
  8. <classname>Zend_Rest_Server</classname> is intended as a fully-featured REST server.
  9. </para>
  10. </sect2>
  11. <sect2 id="zend.rest.server.usage">
  12. <title>REST Server Usage</title>
  13. <example id="zend.rest.server.usage.example-1">
  14. <title>Basic Zend_Rest_Server Usage - Classes</title>
  15. <programlisting language="php"><![CDATA[
  16. $server = new Zend_Rest_Server();
  17. $server->setClass('My_Service_Class');
  18. $server->handle();
  19. ]]></programlisting>
  20. </example>
  21. <example id="zend.rest.server.usage.example-2">
  22. <title>Basic Zend_Rest_Server Usage - Functions</title>
  23. <programlisting language="php"><![CDATA[
  24. /**
  25. * Say Hello
  26. *
  27. * @param string $who
  28. * @param string $when
  29. * @return string
  30. */
  31. function sayHello($who, $when)
  32. {
  33. return "Hello $who, Good $when";
  34. }
  35. $server = new Zend_Rest_Server();
  36. $server->addFunction('sayHello');
  37. $server->handle();
  38. ]]></programlisting>
  39. </example>
  40. </sect2>
  41. <sect2 id="zend.rest.server.args">
  42. <title>Calling a Zend_Rest_Server Service</title>
  43. <para>
  44. To call a <classname>Zend_Rest_Server</classname> service, you must supply a
  45. <constant>GET</constant>/POST <code>method</code> argument with a value that is the
  46. method you wish to call. You can then follow that up with any number
  47. of arguments using either the name of the argument (i.e. "who") or
  48. using <code>arg</code> following by the numeric position of the
  49. argument (i.e. "arg1").
  50. </para>
  51. <note>
  52. <title>Numeric index</title>
  53. <para>
  54. Numeric arguments use a 1-based index.
  55. </para>
  56. </note>
  57. <para>
  58. To call <code>sayHello</code> from the example above, you can use either:
  59. </para>
  60. <para>
  61. <code>?method=sayHello&amp;who=Davey&amp;when=Day</code>
  62. </para>
  63. <para>
  64. or:
  65. </para>
  66. <para>
  67. <code>?method=sayHello&amp;arg1=Davey&amp;arg2=Day</code>
  68. </para>
  69. </sect2>
  70. <sect2 id="zend.rest.server.customstatus">
  71. <title>Sending A Custom Status</title>
  72. <para>
  73. When returning values, to return a custom status, you may return an
  74. array with a <code>status</code> key.
  75. </para>
  76. <example id="zend.rest.server.customstatus.example-1">
  77. <title>Returning Custom Status</title>
  78. <programlisting language="php"><![CDATA[
  79. /**
  80. * Say Hello
  81. *
  82. * @param string $who
  83. * @param string $when
  84. * @return array
  85. */
  86. function sayHello($who, $when)
  87. {
  88. return array('msg' => "An Error Occurred", 'status' => false);
  89. }
  90. $server = new Zend_Rest_Server();
  91. $server->addFunction('sayHello');
  92. $server->handle();
  93. ]]></programlisting>
  94. </example>
  95. </sect2>
  96. <sect2 id="zend.rest.server.customxml">
  97. <title>Returning Custom XML Responses</title>
  98. <para>
  99. If you wish to return custom <acronym>XML</acronym>, simply return a
  100. <code>DOMDocument</code>, <code>DOMElement</code> or
  101. <code>SimpleXMLElement</code> object.
  102. </para>
  103. <example id="zend.rest.server.customxml.example-1">
  104. <title>Return Custom XML</title>
  105. <programlisting language="php"><![CDATA[
  106. /**
  107. * Say Hello
  108. *
  109. * @param string $who
  110. * @param string $when
  111. * @return SimpleXMLElement
  112. */
  113. function sayHello($who, $when)
  114. {
  115. $xml ='<?xml version="1.0" encoding="ISO-8859-1"?>
  116. <mysite>
  117. <value>Hey $who! Hope you\'re having a good $when</value>
  118. <code>200</code>
  119. </mysite>';
  120. $xml = simplexml_load_string($xml);
  121. return $xml;
  122. }
  123. $server = new Zend_Rest_Server();
  124. $server->addFunction('sayHello');
  125. $server->handle();
  126. ]]></programlisting>
  127. </example>
  128. <para>
  129. The response from the service will be returned without modification
  130. to the client.
  131. </para>
  132. </sect2>
  133. </sect1>
  134. <!--
  135. vim:se ts=4 sw=4 et:
  136. -->