Skip to content

Commit 7df529c

Browse files
authored
Update README.md
1 parent f285d77 commit 7df529c

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# yii2-jsonrpc
32

43
This is Yii2-based JSON-RPC server implementation. CURRENTLY IN DEVELOPMENT. CONTRIBUTION WELCOME.
@@ -7,27 +6,26 @@ This is Yii2-based JSON-RPC server implementation. CURRENTLY IN DEVELOPMENT. CON
76
* Uses full Yii2 power, because method string is translated into a route. You can keep using all the Yii2 feature
87
such as routing, access control, etc.
98
Examples:
10-
`{jsonrpc: "2.0", "method": "foo", "id": 1} -> route /foo -> {action: foo, controller: index, module: default}`
11-
`{jsonrpc: "2.0", "method": "foo.bar": "id": 2} -> route /foo/bar -> {action: bar, controller: foo, module: default}`
12-
`{jsonrpc: "2.0", "method": "foo.bar.baz": "id": 3} -> route /foo/bar/baz -> {action: baz, controller: bar, module: foo}`
9+
```
10+
{jsonrpc: "2.0", "method": "foo", "id": 1} -> route /foo -> {action: foo, controller: index, module: default}
11+
{jsonrpc: "2.0", "method": "foo.bar": "id": 2} -> route /foo/bar -> {action: bar, controller: foo, module: default}
12+
{jsonrpc: "2.0", "method": "foo.bar.baz": "id": 3} -> route /foo/bar/baz -> {action: baz, controller: bar, module: foo}
13+
```
1314
* Supports batch processing.
1415

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).
2016

21-
## Examples
17+
## Usage
2218
Entry point:
2319
```php
2420
<?php
2521

2622
namespace app\controllers;
2723

2824
class JsonRpcController extends \georgique\yii2\json-rpc\Controller {
25+
2926
// Practically you don't need anything else in this controller,
3027
// unless you want to customize entry point somehow.
28+
3129
}
3230
```
3331

@@ -36,13 +34,22 @@ Controller with target actions which we are going to call:
3634
<?php
3735
namespace app\modules\api1\controllers;
3836

37+
// There are some minor side-effects of this solutions, because original request is made to the
38+
// entry point, not to the target controller and action. Be careful working with Request object,
39+
// especially when working on access restriction to the target actions. For example, you want an
40+
// action to be reached only with GET verb only, but you do POST request to the endpoint. In that
41+
// case you will get Internal Error because access will be denied.
3942
class ExampleController extends \yii\web\Controller {
4043

41-
44+
// Note that URL patterns won't be used to resolve the method - this would not be resourse-wise.
45+
// Method string should simply be [[module.]controller.]action where module and controller parts
46+
// can be omitted, so default module and index controller will be used.
4247
public function actionTry() {
4348
return "You've got it!";
4449
}
4550

51+
// Method params are directly translated into action arguments. Make sure your call matches action
52+
// signature.
4653
public function actionTryWithParams($foo) {
4754
return "Params received: \$foo = $foo.";
4855
}

0 commit comments

Comments
 (0)