mixinafJsonRpc::JsonRpc

afJsonRpc::JsonRpc

An implementation of JSON-RPC v2.

call

Source

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

Source

static |Obj,Method,Obj?->Obj? convertingInvokeFn(|Type?,Obj?->Obj? fn)

make

Source

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

Creates an instace 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()
])

Valid options are:

  • dispatchFn - |Obj sinks, Str rpcMethod -> Obj[]| { ... }
  • invokeFn - |Obj sink, Method method, Obj? params -> Obj?| { ... }

dispatchFn should return [Obj sink, Method method], or null if the sink / method is not found.

invokeFn should invoke the method on the sink with the given params and return the result.

multiSinkDispatchFn

Source

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('/')
])