Skip to content

Instantly share code, notes, and snippets.

@sergioska
Last active August 29, 2015 13:58
Show Gist options
  • Save sergioska/9956159 to your computer and use it in GitHub Desktop.
Save sergioska/9956159 to your computer and use it in GitHub Desktop.
JSON-RPC service with Zend_Json_Server
<?php
/* path to Zend library*/
set_include_path(__DIR__ . "/libs");
/* include Zend loader (Zend root) */
require_once __DIR__ . "/libs/Zend/Loader.php";
/* load class */
Zend_Loader::loadClass('Zend_Json_Server');
$server = new Zend_Json_Server();
/* service */
$server->setClass('Service');
try {
$server->handle();
} catch(Exception$e) {
header( 'HTTP/1.1 400 BAD REQUEST' );
exit();
}
/* service implementation */
class Service{
public function insert($sName, $sSurname){...}
.....
}
/*
example request
{
"jsonrpc": "2.0",
"method": "insert",
"params": {"name":"sergio", "cognome":"sicari"},
"id": 1
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment