mixinafJsonRpc::JsonRpc
afJsonRpc::JsonRpc
An implementation of JSON-RPC v2.
- call
abstract Str? call(InStream jsonIn, Bool close := true)Invokes the (batch of) RPCs for given JSON request.
The
InStreamis guaranteed to be closed.- convertingInvokeFn
static |Obj,Method,Obj?->Obj? convertingInvokeFn(|Type?,Obj?->Obj? fn)- make
static new make(Obj sink, [Str:Obj?]? opts := null)Creates an instace of
JsonRpc.sinkmay either a single instance, or aStr:Objmap of sink instances whereStris a prefix that must match the RPC method name.jsonRpc := JsonRpc([ "text/" : TextSink() "image/" : ImageSink() ])Valid options are:
dispatchFn-|Obj sinks, Str rpcMethod -> Obj[]| { ... }invokeFn-|Obj sink, Method method, Obj? params -> Obj?| { ... }
dispatchFnshould return[Obj sink, Method method], ornullif the sink / method is not found.invokeFnshould invoke themethodon thesinkwith the givenparamsand return the result.- multiSinkDispatchFn
static |Obj,Str->Obj[]? multiSinkDispatchFn(Int delimiter)An optimised dispatch fn for searching a Map of method prefixs to sink instances.
JsonRpc(..., [ "dispatchFn" : JsonRpc.multiSinkDispatchFn('/') ])