Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 25 days 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 (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-11T09:31:00.000Z (4 months ago)
- Last Synced: 2024-10-01T14:25:11.703Z (about 1 month ago)
- Topics: json-rpc, json-rpc-api, json-rpc-server, json-rpc2, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 104 KB
- Stars: 9
- Watchers: 2
- Forks: 7
- 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.
[![Build Status](https://travis-ci.org/georgique/yii2-jsonrpc.svg?branch=master)](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 [email protected]