Skip to content

Commit 3f4f1d6

Browse files
author
Daniel Bruce
committed
Improved documentation.
Minor rewording, syntax fixes, etc for documentation of the JSON RPC handler.
1 parent b25f395 commit 3f4f1d6

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

docs/handlers/jsonrpc_handler.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# JSON-RPC 1.0 + 2.0 Handler
22

33
The class `Vectorface\SnappyRouter\Handler\JsonRpcHandler` provides a means of
4-
calling class methods via the JSON-RPC protocol. Version 1.0 and 2.0 of the
5-
protocol should both be fully supported.
4+
calling class methods via the
5+
[JSON-RPC](http://json-rpc.org/wiki/specification) protocol. Version 1.0 and
6+
2.0 of the protocol should both be fully supported.
67

78
Some items of interest about this implementation:
9+
810
* Supports batch calls; Many calls in a single request.
911
* Notification calls; Drops responses without a request id.
1012
* Handles both parameter arrays, and named parameters.
1113
* Transparently handles both the JSON-RPC 1.0 and 2.0 spec.
12-
* JSON-RPC 1.0 class hinting *is not supported*. (On purpose.)
14+
* JSON-RPC 1.0 class hinting *is delibrately not supported*.
1315

1416
## Why JSON-RPC?
1517

@@ -22,14 +24,16 @@ identical to a local method call, making it very easy to integrate server-side
2224
calls into client-side or remote code.
2325

2426
API clients can also be simpler too because the local and remote method
25-
signatures can be the same. There is no need to map URLs and/or parameters as in
26-
REST APIs.
27+
signatures can be the same. There is no need to map URLs and/or parameters as
28+
in REST APIs.
2729

2830
For example, one could expose the following class on the server:
2931

3032
```php
3133
<?php
3234

35+
namespace Vendor\MyNamespace\RpcServices;
36+
3337
class Adder
3438
{
3539
public function add($arg1, $arg2)
@@ -39,22 +43,24 @@ class Adder
3943
}
4044
```
4145

42-
The Adder could be called locally as:
46+
The class `Adder` can be called locally as:
47+
4348
```php
44-
$adder = new Adder();
49+
$adder = new Vendor\MyNamespace\RpcServices\Adder();
4550
$adder->add(1, 1); // 2!
4651
```
4752

4853
Or it could be called remotely:
54+
4955
```php
50-
$adder = new $myJsonRpcClient("http://.../Adder"); // Any JSON-RPC client.
56+
$adder = new MyJsonRpcClient("http://.../Adder"); // Any JSON-RPC client.
5157
$adder->add(1, 1); // 2!
5258
```
5359

5460
## Usage
5561

56-
To expose the example Adder class listed in the previous section, one could
57-
configure a router instance as follows:
62+
To expose the example `Adder` class listed in the previous section, configure a
63+
router instance as follows:
5864

5965
```php
6066
<?php
@@ -67,7 +73,7 @@ $config = new Config(array(
6773
Config::KEY_CLASS => 'Vectorface\\SnappyRouter\\Handler\\JsonRpcHandler',
6874
Config::KEY_OPTIONS => array(
6975
Config::KEY_SERVICES => array(
70-
'Adder' => '\Adder' // Adder, as above
76+
'Adder' => 'Vendor\\MyNamespace\\RpcServices\\Adder' // Adder, as above
7177
),
7278
)
7379
)
@@ -78,5 +84,5 @@ echo $router->handleRoute();
7884
```
7985

8086
If the router is called with a URI ending in "Adder(.php)" and a valid JSON-RPC
81-
request POSTed for the method "add", the router should yield a JSON-RPC encoded
82-
response with the sum of the two arguments.
87+
request POSTed for the method "add", the router will response with a JSON-RPC
88+
encoded response with the sum of the two arguments.

0 commit comments

Comments
 (0)