JSONRPC

JSONRPC library takes its roots on Http library, and adds some syntactic sugar for JSONRPC calls.

class JsonRpc.Client(baseUrl, methods, opts)
Arguments
  • baseUrl (string()) – RPC target URL

  • methods (list()) – List of method names to implement

  • opts (object()) – Options

Accepted options are:

http_transaction_factory

A function yielding a transaction. Defaults to Http.Transaction.factory().

For each passed method in methods, an attribute is created on the client object, allowing to directly call the RPC. Each method yields a Deferred.Deferred().

var client = new JsonRpc.Client("http://rpc.example.com/endpoint", [
    "prefix.method",
    "prefix.otherMethod",
    "otherPrefix.method"
]);

client.prefix.method().then(function (data) {
    console.log("prefix.method responded", JSON.stringify(data));
});

client.otherPrefix.method(["some", {parameters: "foo"}]).then(function (data) {
    console.log("otherPrefix.method responded", JSON.stringify(data));
});

Transaction factory may be overridden with debug factory:

var client = new JsonRpc.Client("http://rpc.example.com/endpoint", [
    "prefix.method",
    "prefix.otherMethod",
    "otherPrefix.method"
], {
    http_transaction_factory: Http.Transaction.debug_factory
});

Transaction factory may also be overridden with an OAuth client. See OAuth library documentation for details.