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
InStream
is 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
.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() ])
Valid options are:
dispatchFn
-|Obj sinks, Str rpcMethod -> Obj[]| { ... }
invokeFn
-|Obj sink, Method method, Obj? params -> Obj?| { ... }
dispatchFn
should return[Obj sink, Method method]
, ornull
if the sink / method is not found.invokeFn
should invoke themethod
on thesink
with the givenparams
and 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('/') ])