2017 © Pedro Peláez
 

library json-rpc-client

JSON-RPC 2.0 Client implementation

image

scaytrase/json-rpc-client

JSON-RPC 2.0 Client implementation

  • Wednesday, June 21, 2017
  • by scaytrase
  • Repository
  • 2 Watchers
  • 1 Stars
  • 26,658 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 5 % Grown

The README.md

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight, (*1)

Latest Stable Version Total Downloads Latest Unstable Version, (*2)

JSON-RPC 2.0 Client implementation

Extension of scaytrase/rpc-common, (*3)

  • JSON RPC Interfaces
  • JSON RPC client
  • Async with Guzzle
  • Automatic batch with multiple requests or LazyClientDecorator

JSON-RPC 2.0 Specification, (*4)

Usage

  1. Configure a Guzzle client.
  2. Instantiate the client:
use ScayTrase\Api\JsonRpc\JsonRpcClient;

$client = new JsonRpcClient($guzzleClient, 'http://endpoint/url/');
  1. Optionally pass the ID generator as third argument and the PSR-3 logger as the fourth argument

Simple UUID generator and PSR-3 NullLogger are used by default. ID is generated for RpcRequestInterface instances. If request is instance of JsonRpcRequestInterface and does not contain an ID assigned, the request is traited as notification request and will not receive the response from server., (*5)

  1. Create a RpcRequestInterface instance

With JsonRpcRequest class:, (*6)

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

With JsonRpcNotification class:, (*7)

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

With custom RpcRequestInterface implementation:, (*8)

final class MyRpcRequest implements \ScayTrase\Api\Rpc\RpcRequestInterface 
{
    public function getMethod() 
    {
        return 'my/method';
    }

    public function getParameters() 
    {
        return ['param1' => 'val1'];      
    }
}

$request = new MyRpcRequest;
  1. Call the client
/** @var \ScayTrase\Api\Rpc\RpcClientInterface $client */
/** @var \ScayTrase\Api\Rpc\RpcRequestInterface $request */

$collection = $client->invoke($request);
$collection = $client->invoke([$request]);

The collection object contains the mapping between the requests and the responses, (*9)

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

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

Decorating

Refer scaytrase/rpc-common base library for some useful decorators:, (*10)

  • CacheableRpcClient
  • LazyRpcClient
  • LoggableRpcClient
  • ProfiledClient
  • TraceableClient

The Versions

21/06 2017

dev-master

9999999-dev

JSON-RPC 2.0 Client implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Batanov

28/04 2017

dev-feature/coverage

dev-feature/coverage

JSON-RPC 2.0 Client implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Batanov

28/04 2017

dev-feature/cleanup

dev-feature/cleanup

JSON-RPC 2.0 Client implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Batanov

27/04 2017

1.0.2

1.0.2.0

JSON-RPC 2.0 Client implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Batanov

13/04 2016

1.0.1

1.0.1.0

JSON-RPC 2.0 Client implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Batanov

13/04 2016

1.0

1.0.0.0

JSON-RPC 2.0 Client implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Batanov