PHPackages                             upgate/laravel-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. [API Development](/categories/api)
4. /
5. upgate/laravel-jsonrpc

ActiveLibrary[API Development](/categories/api)

upgate/laravel-jsonrpc
======================

Laravel JSON-RPC 2.0 Server

0.7.11(8mo ago)5141.1k↓16.2%10BSD-2-ClausePHPPHP &gt;=7.2|&gt;=8.0

Since Nov 2Pushed 8mo ago3 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (33)Used By (0)

JSON-RPC Server for Laravel/Lumen
=================================

[](#json-rpc-server-for-laravellumen)

[![Build Status](https://camo.githubusercontent.com/53bec20e72b8bdbe87063beb3d1d4b6ed5617f0728cfda21e7b5e6a2357b98c7/68747470733a2f2f636972636c6563692e636f6d2f67682f7570676174652f6c61726176656c2d6a736f6e7270632e7376673f7374796c653d736869656c64)](https://app.circleci.com/pipelines/github/upgate/laravel-jsonrpc) [![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine/)

### 📢 [Updates from Ukrainian Open Source Community](https://stand-with-ukraine.pp.ua/CommunityUpdates.html)

[](#-updates-from-ukrainian-open-source-community)

### 🇷🇺 [Обращение к гражданам России](https://stand-with-ukraine.pp.ua/ToRussianPeople.html)

[](#-обращение-к-гражданам-россии)

Quick How-To
------------

[](#quick-how-to)

- Install with composer: `composer require upgate/laravel-jsonrpc`
- In your RouteServiceProvider, do something like this:

```
// ...
use Upgate\LaravelJsonRpc\Contract\ServerInterface as JsonRpcServerContract;

class RouteServiceProvider extends ServiceProvider
{
    // ...
    public function map(Router $router)
    {
        $router->group(
            ['namespace' => $this->namespace],
            function (Router $router) {
                // Create an instance of JsonRpcServer
                $jsonRpcServer = $this->app->make(JsonRpcServerContract::class);
                // Set default controller namespace
                $jsonRpcServer->setControllerNamespace($this->namespace);
                // Register middleware aliases configured for Laravel router
                $jsonRpcServer->registerMiddlewareAliases($router->getMiddleware());

                require app_path('Http/routes.php');
            }
        );
    }
}
```

- Use $jsonRpcServer in your routes.php, like this:

```
$router->post('/jsonrpc', function (Illuminate\Http\Request $request) use ($jsonRpcServer) {
    $jsonRpcServer->router()
        ->addMiddlewares(['fooMiddleware', 'barMiddleware', 'auth:rpcGuard']) // Middleware alias names or class names.
                                                                              // Parameters may be specified by separating
                                                                              // the middleware name and parameters with a :
        ->bindController('foo', 'FooController') // for 'foo.$method' methods invoke FooController->$method(),
                                                 // for 'foo' method invoke FooConroller->index()
        ->bind('bar', 'MyController@bar') // for 'bar' method invoke MyController->bar()
        ->group(
            ['bazMiddleware'], // add bazMiddleware for methods in this group
            function ($jsonRpcRouter) {
                // for 'bar.baz' method invoke MyController->bazz()
                $jsonRpcRouter->bind('bar.baz', 'MyController@bazz');
            }
        );

    // Run json-rpc server with $request passed to middlewares as a handle() method argument
    return $jsonRpcServer->run($request);
});
```

See `ServerTest` and `RouterTest` for more examples.

Exception handling
------------------

[](#exception-handling)

Descendants of `Upgate\LaravelJsonRpc\Exception\JsonRpcException` represent JSON-RPC errors according to the spec (see `Upgate\LaravelJsonRpc\Server\ErrorCode`).

Other exceptions are logged and converted to INTERNAL\_ERROR responses by default.

Use `Upgate\LaravelJsonRpc\Server\Server::onException()` to register custom exception handlers:

```
use Upgate\LaravelJsonRpc\Server;

$jsonRpcServer->onException(
    SomeExceptionClass::class,
    function (SomeExceptionClass $e, Server\Request $request = null) {
        $message = "Some Message";
        $code = -32099;
        return Server\RequestResponse::constructErrorResponse($request ? $request->getId() : null, $message, $code);
    }
);

$jsonRpcServer->onException(
    \Throwable::class, // catch-all
    function (\Throwable $e, Server\Request $request = null) {
        $message = "Some Other Message";
        $code = -32098;
        return Server\RequestResponse::constructErrorResponse($request ? $request->getId() : null, $message, $code);
    }
);
```

See `ServerTest:: testSingleRequestWithExceptionHandler()` and `ServerTest::testExceptionHandlersPriority()` for more examples.

JSON-RPC Request Forms
----------------------

[](#json-rpc-request-forms)

(since v0.3.0)

`Upgate\LaravelJsonRpc\Server\FormRequest` is similar to Laravel form requests, but validates JSON-RPC parameters instead.

Example:

```
use Upgate\LaravelJsonRpc\Server\FormRequest as JsonRpcFormRequest;

class MyJsonRpcFormRequest extends JsonRpcFormRequest
{
    public function rules(): array
    {
        return [
            'id'    => 'required|numeric',
            'email' => 'required|email',
        ];
    }
}

class MyController
{
    public function myAction(MyJsonRpcFormRequest $jsonRpcRequest)
    {
        $email = $jsonRpcRequest->email; // or $jsonRpcRequest->get('email');
        $allParams = $jsonRpcRequest->all();
        // ...
    }
}
```

If validation fails, the INVALID\_PARAMS error response is returned, with validation error details in `data.violations`.

See the `ServerFormRequestTest` for more examples.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance59

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 92.8% 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 ~119 days

Recently: every ~299 days

Total

31

Last Release

261d ago

PHP version history (5 changes)0.1.0PHP &gt;=5.5.0

0.2.0PHP &gt;=7.0

0.2.2PHP &gt;=7.1

0.6.0PHP &gt;=7.2

0.7.4PHP &gt;=7.2|&gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a82dee11b9273175f89c77ec185de06aea7f21256c9ac7483e0de7a3420b493?d=identicon)[kbaryshnikov](/maintainers/kbaryshnikov)

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

---

Top Contributors

[![kbaryshnikov](https://avatars.githubusercontent.com/u/7947177?v=4)](https://github.com/kbaryshnikov "kbaryshnikov (90 commits)")[![s-chizhik](https://avatars.githubusercontent.com/u/5587936?v=4)](https://github.com/s-chizhik "s-chizhik (5 commits)")[![Bradez](https://avatars.githubusercontent.com/u/919214?v=4)](https://github.com/Bradez "Bradez (1 commits)")[![sergiizeleniy](https://avatars.githubusercontent.com/u/22545614?v=4)](https://github.com/sergiizeleniy "sergiizeleniy (1 commits)")

---

Tags

laraveljson-rpc

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)

PHPackages © 2026

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