Bundle JSON-RPC 2.0 client and server. Client sends method calls to a remote endpoint and returns typed results; Server dispatches incoming requests to registered handlers. Compile with -lib json_rpc.
Server
JSON RPC server
Operations
New # constructor
Constructor
New(funcs:Hash<String,Func2Ref<JsonElement,JsonElement>>)Parameters
| Name | Type | Description |
|---|---|---|
| funcs | Hash<String,Func2Ref<JsonElement,JsonElement>> | collection of named function calls |
Example
funcs := Hash->New()<String, Func2Ref<JsonElement, JsonElement>>;
# register an "add" method
funcs->Insert("add", Func2Ref->New(\
method(params : JsonElement) ~ JsonElement {
a := params->Get("a")->GetInt();
b := params->Get("b")->GetInt();
return JsonElement->New(a + b);
}));
server := Data.JSON.RPC.Server->New(funcs, 9090);
server->Process(); # blocks, accepts connectionsProcess #
Start the server to accept requests
method : public : Process() ~ NilExample
funcs := Hash->New()<String, Func2Ref<JsonElement, JsonElement>>;
server := Data.JSON.RPC.Server->New(funcs, 9090);
server->Process(); # listen on port 9090 for incoming RPC calls