Programmer's Reference Guide
| Zend_Rest_Client |
Zend_Rest_Server
Introduction
Zend_Rest_Server est prévu comme un serveur supportant l'ensemble des fonctionnalités d'un serveur REST.
Utilisation d'un serveur REST
Exemple #1 Utilisation basique Zend_Rest_Server - Avec des classes
- $server = new Zend_Rest_Server();
- $server->setClass('Mon_Service_Classe');
- $server->handle();
Exemple #2 Utilisation basique Zend_Rest_Server - Avec des fonctions
- /**
- * Dit Bonjour
- *
- * @param string $qui
- * @param string $quand
- * @return string
- */
- function ditBonjour($qui, $quand)
- {
- return "Bonjour $qui, bonne $quand";
- }
- $server = new Zend_Rest_Server();
- $server->addFunction('ditBonjour');
- $server->handle();
Appelé un service Zend_Rest_Server
Pour appeler un service Zend_Rest_Server, vous devez
fournir un argument de method GET/POST avec une valeur qui est la méthode
que vous souhaitez appeler. Vous pouvez alors ajouter tout nombre d'arguments en
utilisant le nom de l'argument (c.-à-d. "qui ") ou en utilisant 'arg' suivi de la
position numérique de l'argument (c.-à-d. "arg1").
Note: Index numérique
Les arguments numériques utilisent 1 comme point de départ.
Pour appeler le ditBonjour de l'exemple ci-dessus, vous pouvez
employer soit :
?method=ditBonjour&qui=Davey&quand=journée
or:
?method=ditBonjour&arg1=Davey&arg2=journée
Envoyer un statut personnalisé
En envoyant des valeurs, pour ajouter un statut personnalisé, vous pouvez envoyer
un tableau avec une clé status.
Exemple #3 Renvoyer un statut personnalisé
- /**
- * Dit Bonjour
- *
- * @param string $qui
- * @param string $quand
- * @return array
- */
- function ditBonjour($qui, $quand)
- {
- }
- $server = new Zend_Rest_Server();
- $server->addFunction('ditBonjour');
- $server->handle();
Renvoyer une réponse XML personnalisée
Si vous voulez retourner du XML personnalisé, retournez simplement un objet
DOMDocument, DOMElement ou
SimpleXMLElement.
Exemple #4 Renvoyer une réponse XML personnalisée
- /**
- * Dit Bonjour
- *
- * @param string $who
- * @param string $when
- * @return SimpleXMLElement
- */
- function ditBonjour($qui, $quand)
- {
- $xml ='<?xml version="1.0" encoding="ISO-8859-1"?>
- <mysite>
- <value>Salut $qui! J\'espère que tu passes une bonne $when</value>
- <constant>200</constant>
- </mysite>';
- $xml = simplexml_load_string($xml);
- return $xml;
- }
- $server = new Zend_Rest_Server();
- $server->addFunction('ditBonjour');
- $server->handle();
La réponse du service sera retournée sans modification au client.
| Zend_Rest_Client |
Add A Comment
Please do not report issues via comments; use the ZF Issue Tracker.
If you have a JIRA/Crowd account, we suggest you login first before commenting.

Comments
I also don't understand what this "Zend_Rest_Server" is supposed to do and why it's useful. "Zend_Rest_Server is intended as a fully-featured REST server." is not enough to explain what this class is intended to be used for. A REST server should be able to:
1. receive and parse a request
2. retrieve, create, update, or delete the requested resource
3. then respond with a representation of the resource in the appropriate format (XML or JSON)
...and that's it! Nothing more. Nothing less.
There is nothing in this documentation that makes me think that Zend_Rest_Server does any of that. How are we even supposed to use this?
I would expect these server and client classes to provide some common framework method on handling requests, responses, errors, GET, POST, PUT, DELETE methods
Like a POST and PUT methods should always return the URI of the resource just got created or updated.
I don't see any such thing in these classes, hence better these should be removed, else programmers will wrongly use these, which is more of SOAP or RPC rest invocation classes.
resources.frontController.plugins.putHandler = "Zend_Controller_Plugin_PutHandler"
it's basically a crappy little helper that checks to see if there's a put request and if so then it puts the variables you're sending along with it into the params. idk why the params aren't included by default when trying to see your vars passed in the putAction
http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.rest
Zend_Rest_Server, as pointed out in this comments, isn't really that useful and is probably on its way out.