Qore JsonRpcHandler Module Reference  1.3

Introduction to the JsonRpcHandler Module

This module implements server-side support for the JSON-RPC protocol for serialization/deserialization of message data accoring to the JSON-RPC specification.

This module provides the JsonRpcHandler class which can be used to provide an RPC handler for the HttpServer class provided by the HttpServer module.

Example Usage

%requires HttpServer
%requires JsonRpcHandler
%requires Mime
const ApiMethods = (
("name": "^sys\\.shutdown\$",
"text": "sys.shutdown",
"function": sub () { background http.stop(); return "OK"; },
"help": "shuts down this server",
"logopt": 0,
),
);
# a logging closure
code log = sub (string str) {printf("%y: %s\n", now_us(), str);};
# our bind address
const Bind = 8888;
JsonRpcHandler jsonRpcHandler(new AbstractAuthenticator(), api);
our HttpServer http(log, log);
http.addListener(Bind);
http.setHandler("jsonrpc", "", MimeTypeJsonRpc, jsonRpcHandler);
http.setDefaultHandler("jsonrpc", jsonRpcHandler);
log("now listening on %s\n", Bind);
http.waitStop();

JsonRpcHandler Release Notes

JsonRpcHandler v1.3

  • updated for JSON-RPC 2.0 support, return JSON-RPC messages with the same protocol level as the request

JsonRpcHandler v1.2

  • fixed bugs handling invalid JSON-RPC messages to give a user-friendly error response
  • converted to new-style

JsonRpcHandler v1.1

  • added an optional log closure to constructor

JsonRpcHandler v1.0

  • updated to a user module