PHP code example of veejay / jsonrpc

1. Go to this page and download the library: Download veejay/jsonrpc 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/ */

    

veejay / jsonrpc example snippets


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;
    }
}

$server = new Server(new MyApi);
echo $response = $server->run();

$client = new Client('https://jsonrpc/server/address');

$query = $client->query('myMethod', ['my_param' => 1]);
$client->notify('myMethod');

$client->send();