PHP code example of scaytrase / json-rpc-client

1. Go to this page and download the library: Download scaytrase/json-rpc-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

scaytrase / json-rpc-client example snippets


use ScayTrase\Api\JsonRpc\JsonRpcClient;

$client = new JsonRpcClient($guzzleClient, 'http://endpoint/url/');

$request = new \ScayTrase\Api\JsonRpc\JsonRpcRequest('my/method', ['param1' => 'val1'], 'request_id');
$notification = new \ScayTrase\Api\JsonRpc\JsonRpcRequest('my/method', ['param1' => 'val1']);

$notification = new \ScayTrase\Api\JsonRpc\JsonRpcNotification('my/method', ['param1' => 'val1']);

final class MyRpcRequest implements \ScayTrase\Api\Rpc\RpcRequestInterface 
{
    public function getMethod() 
    {
        return 'my/method';
    }
    
    public function getParameters() 
    {
        return ['param1' => 'val1'];      
    }
}

$request = new MyRpcRequest;

/** @var \ScayTrase\Api\Rpc\RpcClientInterface $client */
/** @var \ScayTrase\Api\Rpc\RpcRequestInterface $request */
 
$collection = $client->invoke($request);
$collection = $client->invoke([$request]);

/** @var \ScayTrase\Api\Rpc\RpcRequestInterface $request */
/** @var \ScayTrase\Api\Rpc\ResponseCollectionInterface $collection */

$response = $collection->getResponse($request);