PHPackages                             yoanm/jsonrpc-server-sdk - 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. yoanm/jsonrpc-server-sdk

ActiveLibrary[API Development](/categories/api)

yoanm/jsonrpc-server-sdk
========================

Server SDK to convert a json-rpc request string into json-rpc response string

v3.3.6(5mo ago)5207.1k—4.5%3[3 PRs](https://github.com/yoanm/php-jsonrpc-server-sdk/pulls)9MITPHPPHP ^8.0CI passing

Since Apr 1Pushed 5mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (30)Used By (9)

PHP JSON-RPC server sdk
=======================

[](#php-json-rpc-server-sdk)

[![License](https://camo.githubusercontent.com/c3da9db3f836940205d48b0356cd0d9e847f3e9a780f2657bf70bf7c2e677f59/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b2e737667)](https://github.com/yoanm/php-jsonrpc-server-sdk)[![Code size](https://camo.githubusercontent.com/9d9a58e490e1df1303dc834121b54de29ed3f4964b6d80e80efc8c04e4042194/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b2e737667)](https://github.com/yoanm/php-jsonrpc-server-sdk)[![Dependabot Status](https://camo.githubusercontent.com/f9522936b01cc6e3f9df8472586d38ea9298fd08061c34fba9f9d24db0054102/68747470733a2f2f666c61742e62616467656e2e6e65742f6769746875622f646570656e6461626f742f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b)](https://camo.githubusercontent.com/f9522936b01cc6e3f9df8472586d38ea9298fd08061c34fba9f9d24db0054102/68747470733a2f2f666c61742e62616467656e2e6e65742f6769746875622f646570656e6461626f742f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b)[![Last commit](https://camo.githubusercontent.com/cce0b4a0462cf11f7e9c1d0f14e62f2e73e7f6c16ee69e4b56c8a6083fc0d49c/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6173742d636f6d6d69742f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b)](https://camo.githubusercontent.com/cce0b4a0462cf11f7e9c1d0f14e62f2e73e7f6c16ee69e4b56c8a6083fc0d49c/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6173742d636f6d6d69742f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b)

[![Scrutinizer Build Status](https://camo.githubusercontent.com/7c2d019d883a9aa425f036d1d82774f23448e61dc4b511446b7c572b7e6fe45c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b2e7376673f6c6162656c3d5363727574696e697a6572266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-server-sdk/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fc5bc0d34d17dc109a89a37700da33361ddbd44be57c26ef0756c10f1f4cda4b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b2f6d61737465722e7376673f6c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-server-sdk/?branch=master)[![Codacy Badge](https://camo.githubusercontent.com/9fb44e29c9d4bd4ecd206541fbd305938a5a0dbcc15fdab5d1db97a7a24ce23a/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3866333934323461646430343462343361373062646232333865326634386462)](https://www.codacy.com/gh/yoanm/php-jsonrpc-server-sdk/dashboard?utm_source=github.com&utm_medium=referral&utm_content=yoanm/php-jsonrpc-server-sdk&utm_campaign=Badge_Grade)

[![CI](https://github.com/yoanm/php-jsonrpc-server-sdk/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/yoanm/php-jsonrpc-server-sdk/actions/workflows/CI.yml)[![codecov](https://camo.githubusercontent.com/04a8d893f155f36bf71f9421172b31d24568c34688c66990d708bd6dbd08d7d0/68747470733a2f2f636f6465636f762e696f2f67682f796f616e6d2f7068702d6a736f6e7270632d7365727665722d73646b2f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d4e486477454255464b35)](https://codecov.io/gh/yoanm/php-jsonrpc-server-sdk)

[![Latest Stable Version](https://camo.githubusercontent.com/6940b0d094c6520173bfc6ffa6bd1504352662eef9342e8849fd58926691aa3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f616e6d2f6a736f6e7270632d7365727665722d73646b2e737667)](https://packagist.org/packages/yoanm/jsonrpc-server-sdk)[![Packagist PHP version](https://camo.githubusercontent.com/6fec355e0c00333afe6f545677b50b0a5e7d7ddbdba51b7cf05aafe608163b6a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f796f616e6d2f6a736f6e7270632d7365727665722d73646b2e737667)](https://packagist.org/packages/yoanm/jsonrpc-server-sdk)

Simple server SDK to convert a json-rpc request string into json-rpc response string.

See [yoanm/symfony-jsonrpc-http-server](https://github.com/yoanm/symfony-jsonrpc-http-server) for automatic dependency injection.

See [yoanm/jsonrpc-params-symfony-validator-sdk](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk) for params validation.

See [yoanm/jsonrpc-server-doc-sdk](https://github.com/yoanm/php-jsonrpc-server-doc-sdk) for documentation generation.

How to use
----------

[](#how-to-use)

Sdk requires only two things :

- A method resolver : must implements [JsonRpcMethodResolverInterface](./src/Domain/JsonRpcMethodResolverInterface.php), resolving logic's is your own.
- Methods : JsonRpc methods which implements [JsonRpcMethodInterface](./src/Domain/JsonRpcMethodInterface.php)

Sdk optionally provide :

- Events dispatch
- Params validation

### Simple Example

[](#simple-example)

#### JSON-RPC Method

[](#json-rpc-method)

```
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;

class DummyMethod implements JsonRpcMethodInterface
{
    /**
     * {@inheritdoc}
     */
    public function apply(array $paramList = null)
    {
        // Handle the request
        ...
        // Then return a result
        return [
            'status' => 'done',
        ];
        // Or
        return null;
        // Or
        return 12345;
    }
}
```

#### Array method resolver (simple example)

[](#array-method-resolver-simple-example)

*You can use [the one used for behat tests](./features/bootstrap/App/BehatMethodResolver.php) or this [Psr11 method resolver](https://github.com/yoanm/php-jsonrpc-server-sdk-psr11-resolver) as example*

```
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodResolverInterface;

class ArrayMethodResolver implements JsonRpcMethodResolverInterface
{
    /** @var JsonRpcMethodInterface[] */
    private $methodList = [];

    /**
     * {@inheritdoc}
     */
    public function resolve(string $methodName) : ?JsonRpcMethodInterface
    {
        return array_key_exists($methodName, $this->methodList)
            ? $this->methodList[$methodName]
            : null
        ;
    }

    /**
     * @param JsonRpcMethodInterface $method
     * @param string                 $methodName
     */
    public function addMethod(JsonRpcMethodInterface $method, string $methodName)
    {
        $this->methodList[$methodName] = $method;
    }
}
```

Then add your method to the resolver and create the endpoint :

```
use Yoanm\JsonRpcServer\App\Creator\ResponseCreator;
use Yoanm\JsonRpcServer\App\Handler\ExceptionHandler;
use Yoanm\JsonRpcServer\App\Handler\JsonRpcRequestHandler;
use Yoanm\JsonRpcServer\App\Serialization\JsonRpcCallDenormalizer;
use Yoanm\JsonRpcServer\App\Serialization\JsonRpcCallResponseNormalizer;
use Yoanm\JsonRpcServer\App\Serialization\JsonRpcCallSerializer;
use Yoanm\JsonRpcServer\App\Serialization\JsonRpcRequestDenormalizer;
use Yoanm\JsonRpcServer\App\Serialization\JsonRpcResponseErrorNormalizer;
use Yoanm\JsonRpcServer\App\Serialization\JsonRpcResponseNormalizer;
use Yoanm\JsonRpcServer\Infra\Endpoint\JsonRpcEndpoint;

$resolver = new ArrayMethodResolver();
$resolver->addMethod('dummy-method', new DummyMethod());

$jsonRpcSerializer = new JsonRpcCallSerializer(
    new JsonRpcCallDenormalizer(
        new JsonRpcRequestDenormalizer()
    ),
    new JsonRpcCallResponseNormalizer(
        new JsonRpcResponseNormalizer()
        // Or `new JsonRpcResponseNormalizer(new JsonRpcResponseErrorNormalizer())` for debug purpose
        // To also dump arguments, be sure 'zend.exception_ignore_args' ini option is not at true/1
    )
);
$responseCreator = new ResponseCreator();
$requestHandler = new JsonRpcRequestHandler($resolver, $responseCreator);
$exceptionHandler = new ExceptionHandler($responseCreator);

$endpoint = new JsonRpcEndpoint($jsonRpcSerializer, $requestHandler, $exceptionHandler);
```

Once endpoint is ready, you can send it request string :

```
$requestString = listenerList)) {
            return;
        }

        foreach ($this->listenerList[$eventName] as $listener) {
            $listener($event, $eventName);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function addJsonRpcListener(string $eventName, $listener) : void
    {
        $this->listenerList[$eventName][] = $listener;
    }
}
```

Then bind your listeners to your dispatcher:

```
use Yoanm\JsonRpcServer\Domain\Event\Acknowledge\OnRequestReceivedEvent;
use Yoanm\JsonRpcServer\Domain\Event\Acknowledge\OnResponseSendingEvent;
use Yoanm\JsonRpcServer\Domain\Event\Action\OnMethodSuccessEvent;

$dispatcher = new SimpleDispatcher();

$listener = function ($event, $eventName) {
    echo sprintf(
        'Received %s with event class "%s"',
        $eventName,
        get_class($event)
    );
};

$dispatcher->addJsonRpcListener(OnRequestReceivedEvent::EVENT_NAME, $listener);
$dispatcher->addJsonRpcListener(OnResponseSendingEvent::EVENT_NAME, $listener);
$dispatcher->addJsonRpcListener(OnMethodSuccessEvent::EVENT_NAME, $listener);
```

And bind dispatcher like following :

```
$endpoint->setJsonRpcServerDispatcher($dispatcher);
$requestHandler->setJsonRpcServerDispatcher($dispatcher);
$exceptionHandler->setJsonRpcServerDispatcher($dispatcher);
```

#### Events dispatched

[](#events-dispatched)

##### Basic request lifecycle

[](#basic-request-lifecycle)

- `json_rpc_server_skd.on_request_received` / [`Acknowledge\OnRequestReceivedEvent`](./src/Domain/Event/Acknowledge/OnRequestReceivedEvent.php)

    Dispatched when a request has been passed to the endpoint and successfully deserialized.

    > N.B. : Lonely cases where this event is not dispatched are when the request string is not a valid JSON-RPC request.
    >
    > It include :
    >
    >
    > - Parse error exception (malformed json string)
    > - For simple request only, in case of Invalid request (not an object / missing required properties / ...).
    >
    >     *⚠️ For batch request containing Invalid SubRequest, this event will still be dispatched*
- Either

    - `json_rpc_server_skd.on_method_success` / [`Action\OnMethodSuccessEvent`](./src/Domain/Event/Action/OnMethodSuccessEvent.php)

        Dispatched **only in case JSON-RPC method has been successfully executed**.
    - `json_rpc_server_skd.on_method_failure` / [`Action\OnMethodFailureEvent`](./src/Domain/Event/Action/OnMethodFailureEvent.php)

        Dispatched **only in case JSON-RPC method throw an exception during execution**.
- `json_rpc_server_skd.on_response_sending` / [`Acknowledge\OnResponseSendingEvent`](./src/Domain/Event/Acknowledge/OnResponseSendingEvent.php)

    Dispatched when a response has been successfully serialized by the endpoint and will be returned.

##### Additional events

[](#additional-events)

###### Batch request

[](#batch-request)

- `json_rpc_server_skd.on_batch_sub_request_processing` / [`Acknowledge\OnBatchSubRequestProcessingEvent`](./src/Domain/Event/Acknowledge/OnBatchSubRequestProcessingEvent.php)

    Dispatched before that a sub request will be processed.
- `json_rpc_server_skd.on_batch_sub_request_processed` / [`Acknowledge\OnBatchSubRequestProcessedEvent`](./src/Domain/Event/Acknowledge/OnBatchSubRequestProcessedEvent.php)

    Dispatched after that a sub request has been processed (regardless of the success or failure of the sub request method execution).

###### Exception

[](#exception)

`json_rpc_server_skd.on_exception` / [`Action\OnExceptionEvent`](./src/Domain/Event/Action/OnExceptionEvent.php)

Dispatched when an exception occurred during sdk execution

##### Action vs Acknowledge events

[](#action-vs-acknowledge-events)

###### Acknowledge

[](#acknowledge)

They have only an acknowledge purpose.

They are grouped under `Yoanm\JsonRpcServer\Domain\Event\Acknowledge` namespace.

###### Action

[](#action)

They allow you to override stuffs.

They are grouped under `Yoanm\JsonRpcServer\Domain\Event\Action` namespace.

Here, the list :

- [`Action\OnMethodSuccessEvent`](./src/Domain/Event/Action/OnMethodSuccessEvent.php) allow you to update/change the result of the method.
- [`Action\OnMethodFailureEvent`](./src/Domain/Event/Action/OnMethodFailureEvent.php) allow you to update/change the exception thrown by the method.
- [`Action\OnExceptionEvent`](./src/Domain/Event/Action/OnExceptionEvent.php) allow you to update/change the exception thrown.

### Params validation example

[](#params-validation-example)

*You can use this [JSON-RPC params symfony validator](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk) as example*

To validate params for a given method, do the following :

```
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodParamsValidatorInterface;
use Yoanm\JsonRpcServer\Domain\Model\JsonRpcRequest;

$validator = new class implements JsonRpcMethodParamsValidatorInterface
{
    public function validate(JsonRpcRequest $jsonRpcRequest, JsonRpcMethodInterface $method) : array
    {
        if (!(/** Skip unexpected method */)) {
            return [];
        }

        // Create your violations based on what you want
        $paramList = $jsonRpcRequest->getParamList();
        $violation = "???";

        return [$violation];
    }
};

$requestHandler->setMethodParamsValidator($validator);
```

Contributing
------------

[](#contributing)

See [contributing note](./CONTRIBUTING.md)

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance72

Regular maintenance activity

Popularity39

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 96.2% 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

Every ~117 days

Recently: every ~238 days

Total

25

Last Release

156d ago

Major Versions

v0.1.1 → v1.0.02018-04-03

v1.3.0 → v2.0.02018-04-21

v2.0.1 → v3.0.02019-04-19

PHP version history (3 changes)v0.0.1PHP &gt;7.0

v3.0.0PHP &gt;=7.1

v3.2.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4410697?v=4)[yoanm](/maintainers/yoanm)[@yoanm](https://github.com/yoanm)

---

Top Contributors

[![yoanm](https://avatars.githubusercontent.com/u/4410697?v=4)](https://github.com/yoanm "yoanm (178 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![klimov-paul](https://avatars.githubusercontent.com/u/1482054?v=4)](https://github.com/klimov-paul "klimov-paul (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

json-rpcphpsdk

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/yoanm-jsonrpc-server-sdk/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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