Jsonrpc 2.0 for PHP over HTTP(S).
At first you have to extend veejay\jsonrpc\Api class and add required methods:
class MyApi extends Api
{
public function myMethod(array $params)
{
extract($params);
if (!isset($myParam)) {
throw new Exception(Response::INVALID_PARAMS);
}
return 'some result with param: ' . $myParam;
}
}
Then run Server with the following code:
$server = new Server(new MyApi);
echo $response = $server->run();
$client = new Client('https://jsonrpc/server/address');
$query = $client->query('myMethod', ['my_param' => 1]);
$client->notify('myMethod');
$client->send();
You will receive the response from myMethod in $query variable.
- PHP 7.2+
composer require "veejay/jsonrpc"