veejay/jsonrpc

JSONRPC server and client

Maintainers

Package info

github.com/Veejayspb/jsonrpc

pkg:composer/veejay/jsonrpc

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

2.0.0 2026-03-11 09:19 UTC

This package is auto-updated.

Last update: 2026-03-11 09:20:45 UTC


README

Jsonrpc 2.0 for PHP over HTTP(S).

License: MIT

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"