mixinafJsonRpc::JsonRpc

afJsonRpc::JsonRpc

An implementation of JSON-RPC v2.

call

Source

abstract Str? call(InStream jsonIn)

Invokes the (batch of) RPCs for the given JSON request, and returns the JSON response.

null is returned, should the request be a notification.

make

Source

static new make(Obj sink, [Str:Obj]? opts := null)

Creates an instance of JsonRpc.

sink may either a single instance, or a Str:Obj map of sink instances where Str is a prefix that must match the RPC method name.

jsonRpc := JsonRpc([
    "text/"  : TextSink()
    "image/" : ImageSink()
])

Options defaults are:

pathDelimiter : '/'
errFn         : |JsonRpcErr rpcErr                | { }
fromJsonFn    : |Obj? jsonVal, Type argType ->Obj?| { jsonVal }
toJsonFn      : |Obj? returnVal             ->Obj?| { returnVal }
rpcHookFn     : |Obj sink, Method method, Obj?[]? args->Obj?| { method.callOn(sink, args) }

fromJsonFn is used to convert method arguments and toJsonFn is used to convert the method's return value.

rpcHookFn allows you to intercept the final method invocation, make changes, and optionally continue with the invocation.

toImmutableFn

Source

abstract |InStream->Str? toImmutableFn()

Converts this class into an immutable function.

Note that the handler and all options must be immutable too.