veejay / jsonrpc
JSONRPC server and client
v1.0.0
2021-02-22 18:22 UTC
Requires
- php: >=7.2.0
- ext-json: *
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.0.0
This package is auto-updated.
Last update: 2024-10-23 02:14:30 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:
class MyApi extends Api { public function myMethod(array $params) { extract($params); if (!isset($myParam)) { throw new Exception(Response::INVALID_PARAMS); } return 'some result with param: ' . $myParam; } }
Then run Server with the following code:
$server = new Server(new MyApi); echo $response = $server->run();
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 7.2+
Installation
composer require "veejay/jsonrpc"