Last active
August 29, 2015 13:58
-
-
Save sergioska/9956159 to your computer and use it in GitHub Desktop.
JSON-RPC service with Zend_Json_Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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