scaytrase/json-rpc-client
Lightweight PHP JSON-RPC client for calling remote procedures over HTTP. Provides request/response handling, batching, and error parsing, making it easier to integrate JSON-RPC services into your Laravel or vanilla PHP apps with minimal setup.
Extension of scaytrase/rpc-common
LazyClientDecoratoruse ScayTrase\Api\JsonRpc\JsonRpcClient;
$client = new JsonRpcClient($guzzleClient, 'http://endpoint/url/');
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.
RpcRequestInterface instanceWith JsonRpcRequest class:
$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:
$notification = new \ScayTrase\Api\JsonRpc\JsonRpcNotification('my/method', ['param1' => 'val1']);
With custom RpcRequestInterface implementation:
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]);
The collection object contains the mapping between the requests and the responses
/** @var \ScayTrase\Api\Rpc\RpcRequestInterface $request */
/** @var \ScayTrase\Api\Rpc\ResponseCollectionInterface $collection */
$response = $collection->getResponse($request);
Refer scaytrase/rpc-common base library for some
useful decorators:
CacheableRpcClientLazyRpcClientLoggableRpcClientProfiledClientTraceableClientHow can I help you explore Laravel packages today?