JRPC2
JSON-RPC 2.0 library with support of batches and named parameters.
Middlewares:
- Koa Santinell/koa-jrpc2
- Express
- Socket.IO
Transports:
- HTTP
- TCP
- ZeroMQ Santinell/zmqTransport
INSTALL
npm install jrpc2
SERVER EXAMPLES
Using with Koa as middleware:
var rpc = ;var koaMiddleware = ;var route = ;var app = ;var rpcServer = ; rpcServer;
Using with Express as middleware:
var rpc = ;var app = ;var rpcServer = ; rpcServer;
Using with Socket.IO and Express middlewares:
var rpc = ;var http = ;var app = ;var rpcServer = ;var httpServer = http;var io = httpServer; rpcServer;
JSON-RPC modules loaded automatically. Just put it in one directory.
Example of 'math' module with no submodules (./modules/math.js in this example):
moduleexports = { return Promise; } { return Promise; }
Example of 'math' module using submodules (Also ./modules/math.js):
moduleexports = arithmetic: { var sum = 0; for var key in arguments sum+=argumentskey; return Promise; } { var product = 1; for var key in arguments sum *= argumentskey; return Promise; } exponential: { return Promise; } { return promise; } ;
If you want you can manual load your methods and modules.
... var rpcServer = ; var fs = ; rpcServer; rpcServer
Context of methods already extended by request, but you can add some common server context.
... var mongoose = ; rpcServer
And then use this.* in methods:
rpcServer;
CLIENT EXAMPLE
var rpc = ; var http = port: 8080 hostname: 'localhost'; var client = http; //single call with named parameters client; //single call with positional parameters client; //methods and parameters for batch call var methods = "users.auth" "users.auth"; var params = login: "cozy" password: "causeBorn" "admin" "wrong" ; client;