json_rpc/router

Source   Edit  

Types

RpcProc = proc (params: RequestParamsRx): Future[JsonString] {.async.}
Procedure signature accepted as an RPC call by server - if the function has no return value, return JsonString("null") Source   Edit  
RpcRouter = object
  procs*: Table[string, RpcProc]
Source   Edit  

Consts

INTERNAL_ERROR = -32603
Source   Edit  
INVALID_PARAMS = -32602
Source   Edit  
INVALID_REQUEST = -32600
Source   Edit  
JSON_ENCODE_ERROR = -32001
Source   Edit  
JSON_PARSE_ERROR = -32700
Source   Edit  
METHOD_NOT_FOUND = -32601
Source   Edit  
SERVER_ERROR = -32000
Source   Edit  

Procs

proc clear(router: var RpcRouter) {....raises: [], gcsafe, tags: [], forbids: [].}
Source   Edit  
proc hasMethod(router: RpcRouter; methodName: string): bool {....raises: [],
    gcsafe, tags: [], forbids: [].}
Source   Edit  
proc init(T: type RpcRouter): T:type {....raises: [], gcsafe.}
Source   Edit  
proc register(router: var RpcRouter; path: string; call: RpcProc) {....raises: [],
    gcsafe, tags: [], forbids: [].}
Source   Edit  
proc route(router: RpcRouter; data: string | seq[byte]): InternalRaisesFuture[
    string, void] {....stackTrace: false, raises: [], gcsafe, raises: [], gcsafe.}

Route to RPC from string data.

data must be a valid JSON-RPC request or batch request.

Returns the JSON-encoded response.

Source   Edit  
proc route(router: RpcRouter; req: RequestRx2): InternalRaisesFuture[ResponseTx,
    void] {....stackTrace: false, raises: [], gcsafe, raises: [], gcsafe,
            tags: [RootEffect], forbids: [].}
Source   Edit  
proc route(router: RpcRouter; request: RequestBatchRx): InternalRaisesFuture[
    seq[byte], void] {....stackTrace: false, raises: [], gcsafe, raises: [],
                       gcsafe, tags: [RootEffect], forbids: [].}
Routes the request(s) requests and encodes the responses encoded as JSON Source   Edit  
func wrapError(code: int; msg: string): seq[byte] {....raises: [], gcsafe,
    tags: [RootEffect], forbids: [].}
Source   Edit  

Macros

macro rpc(server: RpcRouter; formatType, procList: untyped): untyped {..}
Source   Edit  
macro rpc(server: RpcRouter; path: static[string]; formatType, body: untyped): untyped {..}
Define a remote procedure call. Input and return parameters are defined using the do notation. For example:
myServer.rpc("path") do(param1: int, param2: float) -> string:
  result = $param1 & " " & $param2

Input parameters are automatically marshalled from json to Nim types, and output parameters are automatically marshalled to json for transport.

Source   Edit  

Templates

template rpc(server: RpcRouter; path: string; body: untyped): untyped {..}
Source   Edit