PHPackages                             janderson/json-rpc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. janderson/json-rpc

ActiveLibrary[API Development](/categories/api)

janderson/json-rpc
==================

Minimal JSON-RPC 2.0 implementation

v0.1(1mo ago)01MITPHPPHP &gt;=8.4CI passing

Since Apr 13Pushed 1mo agoCompare

[ Source](https://github.com/jdpanderson/json-rpc)[ Packagist](https://packagist.org/packages/janderson/json-rpc)[ RSS](/packages/janderson-json-rpc/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

JSON-RPC 2.0
============

[](#json-rpc-20)

A library implementing the JSON-RPC 2.0 specification. Another one.

Usage
-----

[](#usage)

### Server

[](#server)

On the server, a request should be read to ensure validity, dispatched, and a response produced.

```
use Janderson\JsonRpc;

$json = '{"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}';
$request = JsonRpc\Request::parse($json); // or ::read($object) with a parsed object or array

$response = is_array($request)
    ? array_filter(array_map(dispatch(...), $request))
    : dispatch($request);

echo json_encode($response);

function dispatch(JsonRpc\Request|JsonRpc\Response $request): JsonRpc\Response|null
{
    // Request error directly produces an error response
    if ($request->isError()) {
        return $request;
    }

    try {
        $result = call_your_function_of_choice($request->method, ...$request->params);
        return JsonRpc\Response::fromResult($result, $request); // Response (result) subtype
    } catch (\Exception $e) {
        return JsonRpc\Response::fromThrowable($e, $request); // Error subtype
    }
}
```

### Client

[](#client)

The client should only have to build a request and handle the response.

```
use Janderson\JsonRpc;

$request = JsonRpc\Request::request('subtract', [2, 1]);
$response = JsonRpc\Response::parse($client->send($request)); // HTTP client, or some other transport
if ($response->isError()) {
    throw new Exception($response->error->message, $response->error->code);
}
echo "Result is {$response->result}\n";
```

Structure
---------

[](#structure)

The structure of the library's classes attempts to follow the JSON-RPC 2.0 specification as closely as possible.

- `Request` and `Response` are the main classes for requests and responses
- `Request` has subtypes `Request\Request` and `Request\Response`
- `Response` has subtypes `Response\Response` and `Response\Error`
- The error field in `Response\Error` has its own type: `Response\Error\Error`

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance88

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

58d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/186284?v=4)[Janderson FFerreira](/maintainers/janderson)[@Janderson](https://github.com/Janderson)

---

Top Contributors

[![jdpanderson](https://avatars.githubusercontent.com/u/4468291?v=4)](https://github.com/jdpanderson "jdpanderson (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/janderson-json-rpc/health.svg)

```
[![Health](https://phpackages.com/badges/janderson-json-rpc/health.svg)](https://phpackages.com/packages/janderson-json-rpc)
```

###  Alternatives

[facebook/php-business-sdk

PHP SDK for Facebook Business

90923.5M35](/packages/facebook-php-business-sdk)[exsyst/swagger

A php library to manipulate Swagger specifications

35916.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
