npm.io
1.0.5 • Published 11 years ago

jsonrpc-express

Licence
MIT
Version
1.0.5
Deps
1
Vulns
0
Weekly
0
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

##jsonrpc-express JSON RPC server as express middleware.

###installation

npm install jsonrpc-express

###usage

Include library

RPCServer = require("jsonrpc-express");

Create server object

var server = new RPCServer({echo:function(args){return {result:args};});

or without arguments

var server = new RPCServer();

Register some methods

server.register("ping", function(args){ return "pong";})

or bulk register

server.register({ping:function(args){return "pong";}, time:function(args){return Date.now();}}

Optionally set authentication handler.

server.setBasicAuth(function(username, password){
    return true; //will accept all passwords
})

Use it as middleware. Multiple server instances can be declared.

var app = express();
app.use("/api", server);

Keywords