Skip to content

Commit f285d77

Browse files
authored
Update README.md
1 parent 2e412c5 commit f285d77

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# yii2-jsonrpc
23

34
This is Yii2-based JSON-RPC server implementation. CURRENTLY IN DEVELOPMENT. CONTRIBUTION WELCOME.
@@ -11,4 +12,55 @@ Examples:
1112
`{jsonrpc: "2.0", "method": "foo.bar.baz": "id": 3} -> route /foo/bar/baz -> {action: baz, controller: bar, module: foo}`
1213
* Supports batch processing.
1314

15+
## Usage notes
16+
* Method is not translated to route as an URL. It should contain actual actual module name, controller and route splitted by dots. So if you have a following URL rule:
17+
`'do-some-stuff' => 'api1/doer/stuff'`
18+
your method string should not be `'do-some-stuff'`, but `'api1.doer.stuff'`. Remember that you are just remotely calling procedures, which in Yii2 terms are actions.
19+
* Note that action is called internally which causes some restrictions on them. One of them is that called action has to approve verb which you use originally for making a JSON-RPC call (most probably it will be GET or POST).
20+
21+
## Examples
22+
Entry point:
23+
```php
24+
<?php
25+
26+
namespace app\controllers;
27+
28+
class JsonRpcController extends \georgique\yii2\json-rpc\Controller {
29+
// Practically you don't need anything else in this controller,
30+
// unless you want to customize entry point somehow.
31+
}
32+
```
33+
34+
Controller with target actions which we are going to call:
35+
```php
36+
<?php
37+
namespace app\modules\api1\controllers;
38+
39+
class ExampleController extends \yii\web\Controller {
40+
41+
42+
public function actionTry() {
43+
return "You've got it!";
44+
}
45+
46+
public function actionTryWithParams($foo) {
47+
return "Params received: \$foo = $foo.";
48+
}
49+
50+
}
51+
```
52+
53+
Now this is how calls and responses will look like:
54+
```
55+
-> {"jsonrpc": "2.0", "method": "api1.example.try", "id": 1}
56+
<- {"jsonrpc": "2.0", "result": "You've got it!", "id": 1}
57+
58+
-> {"jsonrpc": "2.0", "method": "api1.example.try-with-params", "params": {"foo": "bar"}, "id": 2}
59+
<- {"jsonrpc": "2.0", "result": "Params received: $foo = bar.", "id": 2}
60+
61+
-> {"jsonrpc": "2.0", "method": "api1.example.garbage", "id": 3}
62+
<- {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found."}, "id": 3}
63+
```
64+
65+
1466
Author: George Shestayev [email protected]

0 commit comments

Comments
 (0)