1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.rest.server">
4 <title>Zend_Rest_Server</title>
6 <sect2 id="zend.rest.server.introduction">
7 <title>Introduction</title>
10 <classname>Zend_Rest_Server</classname> is intended as a fully-featured REST server.
14 <sect2 id="zend.rest.server.usage">
15 <title>REST Server Usage</title>
17 <example id="zend.rest.server.usage.example-1">
18 <title>Basic Zend_Rest_Server Usage - Classes</title>
20 <programlisting language="php"><![CDATA[
21 $server = new Zend_Rest_Server();
22 $server->setClass('My_Service_Class');
27 <example id="zend.rest.server.usage.example-2">
28 <title>Basic Zend_Rest_Server Usage - Functions</title>
30 <programlisting language="php"><![CDATA[
38 function sayHello($who, $when)
40 return "Hello $who, Good $when";
43 $server = new Zend_Rest_Server();
44 $server->addFunction('sayHello');
50 <sect2 id="zend.rest.server.args">
51 <title>Calling a Zend_Rest_Server Service</title>
54 To call a <classname>Zend_Rest_Server</classname> service, you must supply a
55 GET/POST <code>method</code> argument with a value that is the
56 method you wish to call. You can then follow that up with any number
57 of arguments using either the name of the argument (i.e. "who") or
58 using <code>arg</code> following by the numeric position of the
59 argument (i.e. "arg1").
63 <title>Numeric index</title>
66 Numeric arguments use a 1-based index.
71 To call <code>sayHello</code> from the example above, you can use either:
75 <code>?method=sayHello&who=Davey&when=Day</code>
83 <code>?method=sayHello&arg1=Davey&arg2=Day</code>
87 <sect2 id="zend.rest.server.customstatus">
88 <title>Sending A Custom Status</title>
91 When returning values, to return a custom status, you may return an
92 array with a <code>status</code> key.
95 <example id="zend.rest.server.customstatus.example-1">
96 <title>Returning Custom Status</title>
98 <programlisting language="php"><![CDATA[
103 * @param string $when
106 function sayHello($who, $when)
108 return array('msg' => "An Error Occurred", 'status' => false);
111 $server = new Zend_Rest_Server();
112 $server->addFunction('sayHello');
118 <sect2 id="zend.rest.server.customxml">
119 <title>Returning Custom XML Responses</title>
122 If you wish to return custom <acronym>XML</acronym>, simply return a
123 <code>DOMDocument</code>, <code>DOMElement</code> or
124 <code>SimpleXMLElement</code> object.
127 <example id="zend.rest.server.customxml.example-1">
128 <title>Return Custom XML</title>
130 <programlisting language="php"><![CDATA[
135 * @param string $when
136 * @return SimpleXMLElement
138 function sayHello($who, $when)
140 $xml ='<?xml version="1.0" encoding="ISO-8859-1"?>
142 <value>Hey $who! Hope you\'re having a good $when</value>
146 $xml = simplexml_load_string($xml);
150 $server = new Zend_Rest_Server();
151 $server->addFunction('sayHello');
158 The response from the service will be returned without modification