Json RPC client 1.0 and 2.0 versions for Yii2
Install with composer:
composer require raoptimus/yii2-jsonrpc2
Configuration
return [
//....
'components' =>
'jsonrpc' => [
'class' => raoptimus\jsonrpc2\Connection::class,
'hostname' => 'localhost',
'port' => 8666,
],
];
return [
//....
'components' =>
'jsonrpc' => [
'class' => raoptimus\jsonrpc2\Connection::class,
'unixSocket' => '/tmp/jsonrpc2.sock',
'spec' => raoptimus\jsonrpc2\Connection::SPEC_2_0,
],
];
Use connection
$rpc = \Yii::$app->get('jsonrpc');
$method = "SomeMethodName";
$param = "SomeEnterParam";
$request = $rpc->createRequest($method, [$param]);
$rpc->sendRequest($request);
$result = $rpc->readResponse()->result;
//or
$result = $rpc->$method($param);