dev-master
9999999-dev https://github.com/acelot/json-rpcJSON-RPC 2.0 server for PHP
MIT
server json-rpc
Wallogit.com
2017 © Pedro Peláez
JSON-RPC 2.0 server for PHP
JSON-RPC 2.0 Server for PHP 5.3, (*1)
InvalidArgumentException, Exception)Initialize server. For example you can do this in some route callback or controller action.
By default, the server uses a PhpInput transport, which receives data from php://input.
You can pass custom transport realization via second argument to the server constructor., (*2)
$server = new \Acelot\JsonRpc\Server(new \MyNamespace\MyApi()); $server->dispatch();
Write your API, (*3)
namespace MyNamespace;
class MyApi
{
public function getPost($id)
{
if (empty($id)) {
throw new \InvalidArgumentException('Specify post id');
}
/*
* Post retrieving code here
*/
return $post;
}
public function createPost($title, $body)
{
/*
* Post creating code here. Any exception will be caught and sent to the client in the right form.
*/
return true;
}
}
Now you can call remote procedures via json:, (*4)
{jsonrpc: "2.0", method: "getPost", params: [1], id: null}, (*5)
or, (*6)
{jsonrpc: "2.0", method: "createPost", params: ["New post", "Hello, world!"], id: null}, (*7)
PHP 5.3 or higher, (*8)
This project is released under the MIT public license., (*9)
JSON-RPC 2.0 server for PHP
MIT
server json-rpc