Improve batch call example and wrapper comments (#214)
This commit is contained in:
parent
171c747584
commit
47cfc8916f
14
README.md
14
README.md
|
@ -394,6 +394,20 @@ You can use:
|
||||||
let bmiIndex = await client.bmi(120.5, 12.0)
|
let bmiIndex = await client.bmi(120.5, 12.0)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or you can use batch call to send multiple request at once to the server.
|
||||||
|
|
||||||
|
```Nim
|
||||||
|
let batch = client.prepareBatch()
|
||||||
|
batch.bmi(120.5, 12.0)
|
||||||
|
batch.bmi(120.5, 13.0)
|
||||||
|
batch.bmi(120.5, 14.0)
|
||||||
|
let res = await batch.send()
|
||||||
|
|
||||||
|
# But you need to manually process the response e.g. decode from JSON to
|
||||||
|
# your expected type because you can mix various rpc method call in one batch
|
||||||
|
# with various return type.
|
||||||
|
```
|
||||||
|
|
||||||
This allows you to leverage Nim's static type checking whilst also aiding readability and providing a unified location to declare client side RPC definitions.
|
This allows you to leverage Nim's static type checking whilst also aiding readability and providing a unified location to declare client side RPC definitions.
|
||||||
|
|
||||||
## Working with client transports
|
## Working with client transports
|
||||||
|
|
|
@ -67,6 +67,13 @@ proc createRpcFromSig*(clientType, rpcDecl: NimNode, alias = NimNode(nil)): NimN
|
||||||
## reqParams.positional.add encode(JrpcConv, paramB).JsonString
|
## reqParams.positional.add encode(JrpcConv, paramB).JsonString
|
||||||
## let res = await client.call("rpcApi", reqParams)
|
## let res = await client.call("rpcApi", reqParams)
|
||||||
## result = decode(JrpcConv, res.string, typeof RetType)
|
## result = decode(JrpcConv, res.string, typeof RetType)
|
||||||
|
##
|
||||||
|
## 2nd version to handle batch request after calling client.prepareBatch()
|
||||||
|
## proc rpcApi(batch: RpcBatchCallRef; paramA: TypeA; paramB: TypeB) =
|
||||||
|
## var reqParams = RequestParamsTx(kind: rpPositional)
|
||||||
|
## reqParams.positional.add encode(JrpcConv, paramA).JsonString
|
||||||
|
## reqParams.positional.add encode(JrpcConv, paramB).JsonString
|
||||||
|
## batch.batch.add RpcBatchItem(meth: "rpcApi", params: reqParams)
|
||||||
|
|
||||||
# Each input parameter in the rpc signature is converted
|
# Each input parameter in the rpc signature is converted
|
||||||
# to json using JrpcConv.encode.
|
# to json using JrpcConv.encode.
|
||||||
|
|
Loading…
Reference in New Issue