| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.rest.server">
- <title>Zend_Rest_Server</title>
- <sect2 id="zend.rest.server.introduction">
- <title>Introduction</title>
- <para>
- <classname>Zend_Rest_Server</classname> is intended as a fully-featured REST server.
- </para>
- </sect2>
- <sect2 id="zend.rest.server.usage">
- <title>REST Server Usage</title>
- <example id="zend.rest.server.usage.example-1">
- <title>Basic Zend_Rest_Server Usage - Classes</title>
- <programlisting language="php"><![CDATA[
- $server = new Zend_Rest_Server();
- $server->setClass('My_Service_Class');
- $server->handle();
- ]]></programlisting>
- </example>
- <example id="zend.rest.server.usage.example-2">
- <title>Basic Zend_Rest_Server Usage - Functions</title>
- <programlisting language="php"><![CDATA[
- /**
- * Say Hello
- *
- * @param string $who
- * @param string $when
- * @return string
- */
- function sayHello($who, $when)
- {
- return "Hello $who, Good $when";
- }
- $server = new Zend_Rest_Server();
- $server->addFunction('sayHello');
- $server->handle();
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.rest.server.args">
- <title>Calling a Zend_Rest_Server Service</title>
- <para>
- To call a <classname>Zend_Rest_Server</classname> service, you must supply a
- <constant>GET</constant>/POST <code>method</code> argument with a value that is the
- method you wish to call. You can then follow that up with any number
- of arguments using either the name of the argument (i.e. "who") or
- using <code>arg</code> following by the numeric position of the
- argument (i.e. "arg1").
- </para>
- <note>
- <title>Numeric index</title>
- <para>
- Numeric arguments use a 1-based index.
- </para>
- </note>
- <para>
- To call <code>sayHello</code> from the example above, you can use either:
- </para>
- <para>
- <code>?method=sayHello&who=Davey&when=Day</code>
- </para>
- <para>
- or:
- </para>
- <para>
- <code>?method=sayHello&arg1=Davey&arg2=Day</code>
- </para>
- </sect2>
- <sect2 id="zend.rest.server.customstatus">
- <title>Sending A Custom Status</title>
- <para>
- When returning values, to return a custom status, you may return an
- array with a <code>status</code> key.
- </para>
- <example id="zend.rest.server.customstatus.example-1">
- <title>Returning Custom Status</title>
- <programlisting language="php"><![CDATA[
- /**
- * Say Hello
- *
- * @param string $who
- * @param string $when
- * @return array
- */
- function sayHello($who, $when)
- {
- return array('msg' => "An Error Occurred", 'status' => false);
- }
- $server = new Zend_Rest_Server();
- $server->addFunction('sayHello');
- $server->handle();
- ]]></programlisting>
- </example>
- </sect2>
- <sect2 id="zend.rest.server.customxml">
- <title>Returning Custom XML Responses</title>
- <para>
- If you wish to return custom <acronym>XML</acronym>, simply return a
- <code>DOMDocument</code>, <code>DOMElement</code> or
- <code>SimpleXMLElement</code> object.
- </para>
- <example id="zend.rest.server.customxml.example-1">
- <title>Return Custom XML</title>
- <programlisting language="php"><![CDATA[
- /**
- * Say Hello
- *
- * @param string $who
- * @param string $when
- * @return SimpleXMLElement
- */
- function sayHello($who, $when)
- {
- $xml ='<?xml version="1.0" encoding="ISO-8859-1"?>
- <mysite>
- <value>Hey $who! Hope you\'re having a good $when</value>
- <code>200</code>
- </mysite>';
- $xml = simplexml_load_string($xml);
- return $xml;
- }
- $server = new Zend_Rest_Server();
- $server->addFunction('sayHello');
- $server->handle();
- ]]></programlisting>
- </example>
- <para>
- The response from the service will be returned without modification
- to the client.
- </para>
- </sect2>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|