mixinafJsonRpc::JsonRpc
afJsonRpc::JsonRpc
An implementation of JSON-RPC v2.
- call
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
static new make(Obj sink, [Str:Obj]? opts := null)
Creates an instance of
JsonRpc
.sink
may either a single instance, or aStr:Obj
map of sink instances whereStr
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 andtoJsonFn
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
abstract |InStream->Str? toImmutableFn()
Converts this class into an immutable function.
Note that the handler and all options must be immutable too.