PHPackages                             igaponov/jsonrpc - 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. igaponov/jsonrpc

ActiveLibrary

igaponov/jsonrpc
================

JsonRpc 2.0 PHP Specification

v1.0(11y ago)236MITPHPPHP &gt;=5.4

Since Apr 29Pushed 11y ago1 watchersCompare

[ Source](https://github.com/igaponov/jsonrpc)[ Packagist](https://packagist.org/packages/igaponov/jsonrpc)[ Docs](https://github.com/igaponov/jsonrpc)[ RSS](/packages/igaponov-jsonrpc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

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

[](#json-rpc-20-specification)

[JSON-RPC](http://www.jsonrpc.org/specification) is a stateless, light-weight remote procedure call (RPC) protocol.

[![Build Status](https://camo.githubusercontent.com/938a44bad1a61cdf90f522a1e90ab5fe0718f535ab80870f6d2bdd03d1d6d733/68747470733a2f2f7472617669732d63692e6f72672f696761706f6e6f762f6a736f6e7270632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/igaponov/jsonrpc)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c7e350e556c99ee96524ca273a8c8bbb5854f15eff77753904ab4a80c2bb565c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696761706f6e6f762f6a736f6e7270632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/igaponov/jsonrpc/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/a20579ca517f2d5dc6f9de410ca0fd6be80b800607938c014aeb39bb22e41a90/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696761706f6e6f762f6a736f6e7270632f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/igaponov/jsonrpc/?branch=master)

Request object
--------------

[](#request-object)

A rpc call is represented by sending a [Request object](http://www.jsonrpc.org/specification#request_object) to a Server.

```
// client
$request = new \JsonRpc\Spec\Request('subtract', [42, 23], 1);

// server
$result = call_user_func_array($request->getMethod(), $request->getParams());
```

### Notification

[](#notification)

A [Notification](http://www.jsonrpc.org/specification#notification) is a Request object without an "id" member.

```
$request1 = new \JsonRpc\Spec\Request('update', [1,2,3,4,5]);
$request2 = new \JsonRpc\Spec\Request('foobar');
```

Response object
---------------

[](#response-object)

When a rpc call is made, the Server MUST reply with a [Response](http://www.jsonrpc.org/specification#response_object), except for in the case of Notifications.

```
$response = new \JsonRpc\Spec\Response($result, null, $request->getId());
```

### Error object

[](#error-object)

When a rpc call encounters an error, the Response Object MUST contain the [Error](http://www.jsonrpc.org/specification#error_object) member with a value that is a \\JsonRpc\\Spec\\Error

```
$error = new \JsonRpc\Spec\Error(500, 'Internal error', $exception->getTraceAsString());
$response = new \JsonRpc\Spec\Response(null, $error, $request->getId());
```

The error codes from and including -32768 to -32000 are reserved for pre-defined errors.

```
use \JsonRpc\Spec\Exception\ParseErrorException;

try {
    // parse request
    throw new ParseErrorException();
} catch(ParseErrorException $e) {
    $error = new \JsonRpc\Spec\Error($e->getCode(), $e->getMessage(), $e->getTraceAsString());
    $response = new \JsonRpc\Spec\Response(null, $error, $request->getId());
}
```

Batch
-----

[](#batch)

To send several Request objects at the same time, the Client MAY send an [Array](http://www.jsonrpc.org/specification#batch) filled with Request objects.

```
foreach($batch as $response) {
    $result = $response->getResult();
}
```

### BatchRequest

[](#batchrequest)

```
$requests = [
    new \JsonRpc\Spec\Request('update', [1,2,3,4,5]),
    new \JsonRpc\Spec\Request('foobar'),
    // ...
];
$batch = new \JsonRpc\Spec\BatchRequest($requests);
```

### BatchResponse

[](#batchresponse)

```
$responses = [
    new \JsonRpc\Spec\Response(7, 1),
    new \JsonRpc\Spec\Response(null, $error, 2),
    // ...
];
$batch = new \JsonRpc\Spec\BatchResponse($responses);
```

ObjectManager
-------------

[](#objectmanager)

Object manager is a wrapper for dealing with requests/responses

```
$manager = new \JsonRpc\ObjectManager($transport);
$id = $manager->addRequest('subtract', [42, 23]);
$manager->addNotification('foobar');
$manager->commit();
if (!$manager->hasError($id)) {
    $result = $manager->getResult($id); // 19
} else {
    throw new Exception($manager->getError($id), $manager->getErrorCode($id));
}
```

### Transport

[](#transport)

The object manager uses a transport object to communicate with a transport layer (http, rabbitmq, etc). The transport object must implements the [\\JsonRpc\\TransportInterface](src/JsonRpc/TransportInterface.php).

```
class CurlTransport implements \JsonRpc\TransportInterface
{
    public function send(UnitInterface $data)
    {
        $ch = curl_init();

        $data = json_encode($data);

        curl_setopt($ch, CURLOPT_URL, 'http://localhost/rpc.php');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        curl_exec($ch);
    }
}
```

Testing
-------

[](#testing)

```
$ phpunit
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

4037d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c7c850e385fb61dec398c3088a7000f7ea8adb9e6e2d360e57e0b63115cca1ed?d=identicon)[igaponov](/maintainers/igaponov)

---

Top Contributors

[![igaponov](https://avatars.githubusercontent.com/u/4271889?v=4)](https://github.com/igaponov "igaponov (25 commits)")

---

Tags

specificationjson-rpc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/igaponov-jsonrpc/health.svg)

```
[![Health](https://phpackages.com/badges/igaponov-jsonrpc/health.svg)](https://phpackages.com/packages/igaponov-jsonrpc)
```

###  Alternatives

[swagger-api/swagger-ui

 Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

28.7k45.4M99](/packages/swagger-api-swagger-ui)[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)[kphoen/rulerz

Powerful implementation of the Specification pattern

8831.3M6](/packages/kphoen-rulerz)[darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

3372.3M3](/packages/darkaonline-swagger-lume)[happyr/doctrine-specification

Specification Pattern for your Doctrine repositories

452915.0k8](/packages/happyr-doctrine-specification)

PHPackages © 2026

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