What's the problem with the Zend Framework documentation on Zend_Rest_Server
? There is an absolutely minimalistic example on how to use Zend_Rest_Server:
/**
* 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();
Or do you have any specific problem?
EDIT:
Regarding your question about the MVC integration I think, that this would introduce an extrem overhead together with a lot of functionality you don't need for webservices. Nevertheless I should be possible to integrate the service in to the MVC without any major problems (barring the overhead).
class Hello
{
/**
* Say Hello
*
* @param string $who
* @param string $when
* @return string
*/
function sayHello($who, $when)
{
return "Hello $who, Good $when";
}
}
class ApiController extends Zend_Controller_Action
{
/**
* @var Zend_Rest_Server
*/
protected $_server;
public function init()
{
// disable view rendering
$this->_helper->viewRenderer->setNeverRender(true);
// disable layout (if you use layouts)
$this->_helper->layout->disableLayout();
$this->_server = new Zend_Rest_Server();
$this->_server->setClass('Hello');
}
public function __call($method, $args)
{
$params = $this->_getAllParams();
$params['method'] = $method;
$this->_server->handle($params);
}
}
/*
* This should allow you to call http://www.example.com/api/sayHello/who/MyName/when/morning
* By defining custom routes you're able to control the urls.
*/
Please be aware that the code is untested and surely needs some tweaking especially regarding the error handling but it can serve as a simple MVC service example.