Multi transport JSON-RPC client/server with SSL support for node.js
Can be used as stand alone server or as net.Server/express middleware
npm install jsonrpc-node
Include library
Server = require("jsonrpc-node").TCP.Server;
or over http
Server = require("jsonrpc-node").HTTP.Server;
Create server object
var server = new Server({echo:function(args, reply){return reply(args);}});
or without arguments
var server = new Server();
Register some methods
server.register("ping", function(args, reply){
reply("pong");
reply.notify("pong2"); //data can be streamed
});
or bulk register
server.register({ping:function(args, reply){reply("pong");}, time:function(args, reply){return reply.error("some error");}});
Start listening
server.listen(3001, "localhost")
or use SSL connection
server.listenSSL(3001, "localhost","key.pem","cert.pem");
or can be used as middleware,
tcp server for net.Server
net.createServer(server)
http server for express
var app = express();
app.use("/api", server);
Include library
Client = require("jsonrpc-node").TCP.Client;
or
Client = require("jsonrpc-node").HTTP.Client;
Create client object
client = new Client(3001, "localhost");
Execute remote methods
client.call("multiply", [1,2,4], function(err, result){})