PHPackages                             eugene-khorev/yii2-json-rpc-controller - 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. [Framework](/categories/framework)
4. /
5. eugene-khorev/yii2-json-rpc-controller

ActiveYii2-extension[Framework](/categories/framework)

eugene-khorev/yii2-json-rpc-controller
======================================

Yii2 JSON RPC 2.0 extension

01801PHP

Since Nov 27Pushed 9y ago3 watchersCompare

[ Source](https://github.com/eugene-khorev/yii2-json-rpc-controller)[ Packagist](https://packagist.org/packages/eugene-khorev/yii2-json-rpc-controller)[ RSS](/packages/eugene-khorev-yii2-json-rpc-controller/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Basic usage
===========

[](#basic-usage)

Change your request component class in configuration to `\jsonrpc\Request`:

```
   'components' => [
		...
        'request' => [
            'class' => 'jsonrpc\Request',
            'cookieValidationKey' => '...',
        ],
		...
	]
```

Create a new controller that extends `\jsonrpc\Controller`:

```
class SomeController extends \jsonrpc\Controller
{
	/**
	 * This is regular controller action
	 */
	public function actionIndex()
	{
		return $this->render('index');
	}

	/**
	 * This is JSON-RPC 2.0 controller action
	 */
	public function rpcEcho($param1, $param2)
	{
		return ['recievedData' => ['param1' => $param1, 'param1' => $param1]];
	}
}
```

Now if you post this JSON-RPC 2.0 request to `/some/rpc`:

```
{
	"jsonrpc": "2.0",
	"method": "echo",
	"params": {
		"param1": "abc",
		"param2": "123"
	},
	"id": 1
}
```

You get the following result

```
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"recievedData": {
			"param1": "abc",
			"param2": "123"
		}
	}
}
```

And if you navigate your browser to `/some/index` you get regular `\Yii2\web\Controller` behavoir.

Advanced usage
==============

[](#advanced-usage)

Parameters, models and validation
---------------------------------

[](#parameters-models-and-validation)

Create a new model:

```
class SomeModel extends yii\base\Model
{
	public $value1;
	public $value2;
}
```

Make changes to you RPC controller action so it looks like this:

```
	public function rpcEcho($param1, SomeModel $modelParam)
	{
		return ['recievedData' => [
					'param1' => $param1,
					'modelParam' => $modelParam->attributes
		]];
	}
```

Now if you post this JSON-RPC 2.0 request to `/some/rpc`:

```
{
	"jsonrpc": "2.0",
	"params": {
		"param1": "abc",
		"modelParam": {
			"value1": "123",
			"value2": "321",
		}
	},
	"id": 1
}
```

You get valid `$modelParam` model in your method. The library uses `rpc` or `default` scenario to validate parameter models. If validation fails a client recieves correct JSON-RPC 2.0 answer containing validation error, but your RPC action method doesn't even run.

Batch requests
--------------

[](#batch-requests)

You can also use batch JSON-RPC 2.0 requests:

```
[
	{
		"jsonrpc": "2.0",
		"method": "some-method",
		"params": { "something": "anything"},
		"id": 1
	},
	{
		"jsonrpc": "2.0",
		"method": "another-method",
		"params": { "data": [1, 2, 3, 4] },
		"id": 2
	}
]
```

In this case two controller methods `rpcSomeMethod()` and `rpcAnotherMethod()` will be called sequentially. And the client will recieve the correct batch results event if there are errors occurred in one of the methods.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfe7f256645a4f64f8a4b5447e76f5ca5e86044767f16186682d25ef6c8320b0?d=identicon)[eugene-khorev](/maintainers/eugene-khorev)

---

Top Contributors

[![eugene-khorev](https://avatars.githubusercontent.com/u/10964720?v=4)](https://github.com/eugene-khorev "eugene-khorev (12 commits)")[![e-khorev-estp-ru](https://avatars.githubusercontent.com/u/11005279?v=4)](https://github.com/e-khorev-estp-ru "e-khorev-estp-ru (7 commits)")

### Embed Badge

![Health badge](/badges/eugene-khorev-yii2-json-rpc-controller/health.svg)

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

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M297](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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