Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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]