veejay / jsonrpc
JSONRPC server and client
2.0.0
2026-03-11 09:19 UTC
Requires
- php: >=8.0
Requires (Dev)
- nyholm/nsa: ^1.3
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2026-03-11 09:20:45 UTC
README
Jsonrpc 2.0 for PHP over HTTP(S).
Examples
Server
At first, you have to extend Veejay\Jsonrpc\Api class and add required methods:
<?php use Veejay\Jsonrpc\Api; use Veejay\Jsonrpc\Exception\InvalidParamsException; class MyApi extends Api { public function myMethod(array $params): string { extract($params); if (!isset($myParam)) { throw new InvalidParamsException; } return 'some result with param: ' . $myParam; } }
Then run Server with the following code:
<?php use Veejay\Jsonrpc\Server; $server = new Server(new MyApi); echo $response = $server->run();
Client
<?php use Veejay\Jsonrpc\Client; $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.
Requirements
- PHP 8.0+
Installation
composer require "veejay/jsonrpc"