PHPackages                             boomdraw/rpc-core - 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. boomdraw/rpc-core

ActiveLibrary[API Development](/categories/api)

boomdraw/rpc-core
=================

Lumen JSON-RPC concern

v1.0.1(5y ago)013MITPHPPHP ^7.4|^8.0CI failing

Since Jul 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/boomdraw/rpc-core)[ Packagist](https://packagist.org/packages/boomdraw/rpc-core)[ RSS](/packages/boomdraw-rpc-core/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

Lumen JSON-RPC core
===================

[](#lumen-json-rpc-core)

Allows [Lumen](https://lumen.laravel.com/) to handle [JSON-RPC 2.0](https://www.jsonrpc.org/specification) requests and return [JSON-RPC 2.0](https://www.jsonrpc.org/specification) responses.

[![Build Status](https://camo.githubusercontent.com/0da777dabec888a4a9315f361cea50e606de9c0806a521775f034c805e40f635/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f626f6f6d647261772f7270632d636f72652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/boomdraw/rpc-core)[![StyleCI](https://camo.githubusercontent.com/0d6bb5aa442b93bac53c69b7832d8601d95d849076845fbde3736fc0453af69a/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3238323436313536372f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/282461567)[![Code Coverage](https://camo.githubusercontent.com/88b54440d602e22872ed5765b82f9ce7154c820fe91359780cdf50486e243487/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f626f6f6d647261772f7270632d636f72652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/boomdraw/rpc-core)[![Quality Score](https://camo.githubusercontent.com/a6a102c8a7e186713d6c509c4b54c9d68919a76b2ca0ffcb650e897aa32bac62/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f626f6f6d647261772f7270632d636f72652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/boomdraw/rpc-core)[![Latest Version on Packagist](https://camo.githubusercontent.com/167fe32be7b57c296857ff26ba24a548e50d8b949a7714fac50b96b1bf221ddf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626f6f6d647261772f7270632d636f72653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boomdraw/rpc-core)[![Total Downloads](https://camo.githubusercontent.com/e59dd3f835345421fe113c9cdfe00049aac2c1f4c4b9d05fa51ba6d4a85f419a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626f6f6d647261772f7270632d636f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boomdraw/rpc-core)[![PHP Version](https://camo.githubusercontent.com/0fb59399789231a2d0df3287b3a6fd9d0c95a70113c52a4ea7547cb7eee38246/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f626f6f6d647261772f7270632d636f72653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boomdraw/rpc-core)[![License](https://camo.githubusercontent.com/a74d82d04fa8d332a220406a9e1f10ae087634f54f4ec86db8e20e03d38b6f30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626f6f6d647261772f7270632d636f72653f7374796c653d666c61742d7371756172653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boomdraw/rpc-core)

This package provides a request manager that passes the request to the RpcRequests or default RoutesRequests dispatcher.

Version compatibility
---------------------

[](#version-compatibility)

LumenJSON-RPC core6.x1.x7.x1.x8.x1.xInstallation
------------

[](#installation)

Via Composer

```
$ composer require boomdraw/rpc-core
```

Change the Application class in the bootstrap file to `Boomdraw\RpcCore\Application`or provide your own Application class with `Boomdraw\RpcCore\Concerns\RequestManager` trait:

```
// bootstrap/app.php

$app = new Boomdraw\RpcCore\Application(
    dirname(__DIR__)
);
```

Change exception handler:

```
// bootstrap/app.php

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    Boomdraw\RpcCore\Handler::class
);
```

Your Lumen application is ready to handle JSON-RPC requests!

Usage
-----

[](#usage)

### RPC endpoint

[](#rpc-endpoint)

RPC concern handles only `POST` requests to the specific endpoint.

By default, it uses current application version `config('app.version', '1.0')` as a route path (`POST /v1.0`).

You can provide a custom RPC path by setting it in the app config file:

```
// config/app.php

return [
    ...
    'rpc' => 'my-custom-uri',
    ...
];
```

### Disable JSON-RPC requests

[](#disable-json-rpc-requests)

You can disable the RPC dispatcher in the `config/app.php` config file:

```
// config/app.php

return [
    ...
    'rpc' => false,
    ...
];
```

### Disable routes requests

[](#disable-routes-requests)

If you want to use your application as RPC only, you can disable default routes dispatcher in the `config/app.php` config file:

```
// config/app.php

return [
    ...
    'routes' => false,
    ...
];
```

### JSON-RPC Handlers

[](#json-rpc-handlers)

Behind the scene, JSON-RPC handlers logic is the same as Controllers. It works with global and routes middleware. You can provide middleware for a handler or its specific method the same way as for [Controller](https://lumen.laravel.com/docs/7.x/controllers#controller-middleware).

The handler should extend `Boomdraw\RpcCore\Handler` class to have the same capabilities as the controller.

#### Handlers namespace and naming

[](#handlers-namespace-and-naming)

By default, JSON-RPC requests concern will look for handlers with suffix `Handler` in the `App\Rpc\Handlers` namespace. You can change handlers default namespace and/or suffix in the config file.

Create the file `config/rpc.php` with the next content:

```
