https://github.com/georgique/yii2-jsonrpc
Yii2 JSON-RPC server implementation based on method-to-action translation.
https://github.com/georgique/yii2-jsonrpc
json-rpc json-rpc-api json-rpc-server json-rpc2 yii2 yii2-extension
Last synced: about 1 year ago
JSON representation
Yii2 JSON-RPC server implementation based on method-to-action translation.
- Host: GitHub
- URL: https://github.com/georgique/yii2-jsonrpc
- Owner: georgique
- License: bsd-2-clause
- Created: 2017-12-26T05:40:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-11T09:31:00.000Z (almost 2 years ago)
- Last Synced: 2025-03-26T17:01:52.002Z (about 1 year ago)
- Topics: json-rpc, json-rpc-api, json-rpc-server, json-rpc2, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 104 KB
- Stars: 9
- Watchers: 1
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yii2 JSON-RPC
Yii2 extension for JSON-RPC server implementation. Works not as Remote Procedure Call, but Remote Action Call, therefor leaves all Yii2 power for your service.
[](https://travis-ci.org/georgique/yii2-jsonrpc)
## Features
* Uses full Yii2 power, because method string is translated into a route.
* Lightweight.
* Fully [JSON-RPC 2.0](http://www.jsonrpc.org/specification) compliant.
## Usage
Entry point:
```php
request->getBodyParams() as $name => $value) {
$output_chunks[] = "$name = $value\n";
}
return $output . implode(', ', $output_chunks) . '.';
}
}
```
Now this is how calls and responses will look like:
```
-> {"jsonrpc": "2.0", "method": "api1.example.try", "id": 1}
<- {"jsonrpc": "2.0", "result": "You've got it!", "id": 1}
-> {"jsonrpc": "2.0", "method": "api1.example.try-with-params", "params": {"foo": "bar"}, "id": 2}
<- {"jsonrpc": "2.0", "result": "Params received: $foo = bar.", "id": 2}
// Using alternative entry point:
-> {"jsonrpc": "2.0", "method": "api1.example.try-with-body-params", "params": {"foo": "bar", "foo1": "bar1"}, "id": 2}
<- {"jsonrpc": "2.0", "result": "Params received: $foo = bar, $foo1 = bar1.", "id": 2}
-> {"jsonrpc": "2.0", "method": "api1.example.garbage", "id": 3}
<- {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found."}, "id": 3}
-> [
{"jsonrpc": "2.0", "method": "api1.example.try", "id": 1},
{"jsonrpc": "2.0", "method": "api1.example.try-with-params", "params": {"foo": "bar"}, "id": 2},
{"jsonrpc": "2.0", "method": "api1.example.garbage", "id": 3}
]
<- [
{"jsonrpc": "2.0", "result": "You've got it!", "id": 1},
{"jsonrpc": "2.0", "result": "Params received: $foo = bar.", "id": 2},
{"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found."}, "id": 3}
]
```
Author: George Shestayev george.shestayev@gmail.com