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.
Client
JSON RPC client
Operations
Call #
Call remote procedure
method : public : Call(func_name:String, func_params:JsonElement) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| func_name | String | name of function to call |
| func_params | JsonElement | function call parameters |
Return
| Type | Description |
|---|---|
| JsonElement | JSON response |
Example
client := Data.JSON.RPC.Client->New("localhost", 9090);
params := JsonParser->TextToElement("{\"x\": 10}");
result := client->Call("square", params); # invoke remote method
if(result <> Nil) {
result->GetInt()->PrintLine(); # print returned value
};GetLastError #
Get the last error
method : public : GetLastError() ~ Collection.Tuple.Pair<IntRef,String>Return
| Type | Description |
|---|---|
| CollectionTuplePair<IntRef,String> | last error |
Example
client := Data.JSON.RPC.Client->New("localhost", 9090);
params := JsonParser->TextToElement("{}");
result := client->Call("missing_method", params);
if(result = Nil) {
err := client->GetLastError(); # retrieve error code and message
err->GetSecond()->PrintLine();
};New # constructor
Constructor
New(address:String, port:Int)Parameters
| Name | Type | Description |
|---|---|---|
| address | String | server address |
| port | Int | server port |
Example
client := Data.JSON.RPC.Client->New("localhost", 9090);
params := JsonParser->TextToElement("{\"a\": 3, \"b\": 4}");
result := client->Call("add", params);
if(result <> Nil) { result->GetInt()->PrintLine(); }; # 7