PHPackages                             studio451/yii2-json-rpc-2.0-api - 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. [Admin Panels](/categories/admin)
4. /
5. studio451/yii2-json-rpc-2.0-api

ActiveYii2-extension[Admin Panels](/categories/admin)

studio451/yii2-json-rpc-2.0-api
===============================

JSON RPC 2.0 for Yii2 API with CRUD+ actions

v1.0(6y ago)11.0kBSD-3-ClausePHPPHP &gt;=5.4.0

Since Jun 3Pushed 6y agoCompare

[ Source](https://github.com/studio451/yii2-json-rpc-2.0-api)[ Packagist](https://packagist.org/packages/studio451/yii2-json-rpc-2.0-api)[ Docs](https://yii2jsonrpc2api.studio451.ru)[ RSS](/packages/studio451-yii2-json-rpc-20-api/feed)WikiDiscussions master Synced today

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

Yii2 extention for [JSON-RPC 2.0](http://www.jsonrpc.org/specification) API with CRUD+ actions
----------------------------------------------------------------------------------------------

[](#yii2-extention-for-json-rpc-20-api-with-crud-actions)

### Table of Contents

[](#table-of-contents)

- [Features](#features)
- [Using](#using)
- [CRUD+ API actions](#crud-api-actions)
    - [Example Create action](#example-create-action)
    - [Example Update action](#example-update-action)
    - [Example View action](#example-view-action)
    - [Example Delete action](#example-delete-action)
    - [Example DeleteAll action](#example-deleteall-action)
- [List API action](#list-api-action)
    - [Example List action](#example-list-action)

### Features:

[](#features)

1. CRUD API actions
2. List API action
3. DeleteAll API action
4. CORS Support

### Using

[](#using)

Easiest way to use in 4 steps:

1. Install via composer

    in ./composer.json add into 'require' section

    ```
    "studio451/yii2-json-rpc-2.0-api": "1.*"
    ```

    and in console/terminal run

    ```
    composer update
    ```
2. Use namespace in your controller for CRUD+ actions

    ```
    use \studio451\yii2jsonrpc2api\ActiveController;
    ```

    change extends class to

    ```
    class ModelController extends \studio451\yii2jsonrpc2api\ActiveController {

        public $modelClass = 'app\models\Model';
        public $dataFilter = 'app\models\ModelFilter';

        //BODY or empty
        ~~~
    }
    ```
3. Make json request to controller (used pretty urls without index.php). Request method MUST be POST and Content-type MUST be application/json.

### CRUD+ API actions

[](#crud-api-actions)

To call the JSONRPC API, you can use this feature:

```
function sendToJsonrpc2(url, method, params, callback){

    let command = {"jsonrpc": "2.0", "id": createUUID(), "method": method, "params": params};

    command = JSON.stringify(command);

    let request = {
        type: "POST",
        dataType: 'JSON',
        url: '/jsonrpc2/v1/' + url + '?access-token=wKiPsMKbAm1a7Gg09rZ2qg28UWyWMiXN',
        contentType: "application/json",
        data: command
    };

    $.ajax(request).done(function (data) {
        if (callback)
        {
            callback(data);
        }
    });
}

function createUUID() {
    const fmt = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
    const rnd = Array.from(crypto.getRandomValues(new Uint8Array(32))).map(n => n & 0xf);
    const rk = (c, r) => ((c == 'x' ? r : (r & 0x3 | 0x8)).toString(16));
    return fmt.replace(/[xy]/g, c => rk(c, rnd.pop()));
}
```

#### Example Create action

[](#example-create-action)

request:

```
{
  "type": "POST",
  "dataType": "JSON",
  "url": "/jsonrpc2/v1/author",
  "contentType": "application/json",
  "data": {
    "jsonrpc": "2.0",
    "id": "6187d757-9a9b-469b-87d7-54b080304099",
    "method": "create",
    "params": {
      "firstName": "Ray",
      "secondName": "Bradbury"
    }
  }
}
```

and response will be:

```
{
  "jsonrpc": "2.0",
  "id": "6187d757-9a9b-469b-87d7-54b080304099",
  "method": "create",
  "timestamp": 1559548947,
  "result": {
    "firstName": "Ray",
    "secondName": "Bradbury",
    "id": 1,
    "books": []
  }
}
```

#### Example Update action

[](#example-update-action)

request:

```
{
  "type": "POST",
  "dataType": "JSON",
  "url": "/jsonrpc2/v1/author",
  "contentType": "application/json",
  "data": {
    "jsonrpc": "2.0",
    "id": "982f4f47-e72e-4b3c-90f5-f8422a5f90b1",
    "method": "update",
    "params": {
      "id": 1,
      "description": "Ray Douglas Bradbury"
    }
  }
}
```

and response will be:

```
{
  "jsonrpc": "2.0",
  "id": "982f4f47-e72e-4b3c-90f5-f8422a5f90b1",
  "method": "update",
  "timestamp": 1559548983,
  "result": {
    "id": 1,
    "firstName": "Ray",
    "secondName": "Bradbury",
    "description": "Ray Douglas Bradbury",
    "time": 0,
    "status": 1,
    "books": []
  }
}
```

#### Example View action

[](#example-view-action)

request:

```
{
  "type": "POST",
  "dataType": "JSON",
  "url": "/jsonrpc2/v1/author",
  "contentType": "application/json",
  "data": {
    "jsonrpc": "2.0",
    "id": "3670b63a-55d3-40a9-965e-7f61a72858b0",
    "method": "view",
    "params": {
      "id": 1
    }
  }
}
```

and response will be:

```
{
  "jsonrpc": "2.0",
  "id": "3670b63a-55d3-40a9-965e-7f61a72858b0",
  "method": "view",
  "timestamp": 1559549627,
  "result": {
    "id": 1,
    "firstName": "Ray",
    "secondName": "Bradbury",
    "description": null,
    "time": 0,
    "status": 1,
    "books": [
      {
        "id": 1,
        "id_author": 1,
        "title": "Fahrenheit 451",
        "description": null,
        "time": 0,
        "status": 1
      }
    ]
  }
}
```

#### Example Delete action

[](#example-delete-action)

request:

```
{
  "type": "POST",
  "dataType": "JSON",
  "url": "/jsonrpc2/v1/author",
  "contentType": "application/json",
  "data": {
    "jsonrpc": "2.0",
    "id": "5e53b745-25f4-4039-87ab-e72acc5fd827",
    "method": "delete",
    "params": {
      "id": 1
    }
  }
}
```

and response will be:

```
{
  "jsonrpc": "2.0",
  "id": "5e53b745-25f4-4039-87ab-e72acc5fd827",
  "method": "delete",
  "timestamp": 1559549032,
  "result": true
}
```

#### Example DeleteAll action

[](#example-deleteall-action)

request:

```
{
  "type": "POST",
  "dataType": "JSON",
  "url": "/jsonrpc2/v1/book",
  "contentType": "application/json",
  "data": {
    "jsonrpc": "2.0",
    "id": "cd340790-fce7-468b-a5dd-47f1e0a227c0",
    "method": "delete-all",
    "params": {}
  }
}
```

and response will be:

```
{
  "jsonrpc": "2.0",
  "id": "cd340790-fce7-468b-a5dd-47f1e0a227c0",
  "method": "delete-all",
  "timestamp": 1559550202,
  "result": true
}
```

### List API action

[](#list-api-action)

Based on Yii2 ActiveDataProvider and used \\studio451\\yii2jsonrpc2api\\ActiveController::dataFilter

#### Example List action

[](#example-list-action)

request:

```
{
  "type": "POST",
  "dataType": "JSON",
  "url": "/jsonrpc2/v1/book",
  "contentType": "application/json",
  "data": {
    "jsonrpc": "2.0",
    "id": "d159328b-7b55-4b3b-88d5-f97eafce13f9",
    "method": "list",
    "params": {
      "filter": {
        "and": [
          {
            "title": {
              "like": "Fah"
            }
          },
          {
            "id_author": 1
          }
        ]
      },
      "pagination": {
        "pageSize": 25
      },
      "sort": {
        "defaultOrder": {
          "id": 4
        }
      }
    }
  }
}
```

and response will be:

```
{
  "jsonrpc": "2.0",
  "id": "d159328b-7b55-4b3b-88d5-f97eafce13f9",
  "method": "list",
  "timestamp": 1559549743,
  "result": {
    "models": [
      {
        "id": 1,
        "id_author": 1,
        "title": "Fahrenheit 451",
        "description": null,
        "time": 0,
        "status": 1
      }
    ],
    "count": 1,
    "totalCount": 1
  }
}
```

### More info:

[](#more-info)

---

- [Live DEMO](https://yii2jsonrpc2api.studio451.ru)
- [Source of live DEMO](https://github.com/studio451/yii2-json-rpc-2.0-api-live-demo)

#### Contacts

[](#contacts)

[![Yii2](https://camo.githubusercontent.com/d6b0929173e28cc627430d2519ca1853466a70f37395877eaf4820cb3e1e1909/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f77657265645f62792d5969695f4672616d65776f726b2d677265656e2e7376673f7374796c653d666c6174)](https://www.yiiframework.com/)

###  Health Score

27

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

2483d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83b5e3e64cd1540cf6cad4d1bdf6db23978a522c2f00fbaa1a532f55763a3dbd?d=identicon)[studio451](/maintainers/studio451)

---

Top Contributors

[![studio451](https://avatars.githubusercontent.com/u/35504914?v=4)](https://github.com/studio451 "studio451 (6 commits)")

---

Tags

jsonrpcyii2jsonrpccrudyiijson-rpcjsonrpc2json-rpc-2.0rpc2json-rpc2

### Embed Badge

![Health badge](/badges/studio451-yii2-json-rpc-20-api/health.svg)

```
[![Health](https://phpackages.com/badges/studio451-yii2-json-rpc-20-api/health.svg)](https://phpackages.com/packages/studio451-yii2-json-rpc-20-api)
```

###  Alternatives

[cranetm/yii2-json-rpc-2.0

JSON RPC 2.0 for Yii2 strict type validation of request and response data

2679.2k1](/packages/cranetm-yii2-json-rpc-20)[datto/json-rpc

Fully unit-tested JSON-RPC 2.0 for PHP

1961.3M13](/packages/datto-json-rpc)[schmunk42/yii2-giiant

Gii CRUD generator for Yii 2 Framework

276460.8k17](/packages/schmunk42-yii2-giiant)[nizsheanez/yii2-json-rpc

A lightweight JsonRpc Server and Client for PHP

2033.9k](/packages/nizsheanez-yii2-json-rpc)

PHPackages © 2026

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