Package Exports
- json-rpc2
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-rpc2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-jsonrpc2
This is a JSON-RPC server and client library for node.js http://nodejs.org/, the V8 based evented IO framework.
This fork is a rewrite with proper testing and linted code, compatible with node >= 0.8
Install
To install node-jsonrpc2 in the current directory, run:
npm install json-rpc2 --save
Usage
Firing up an efficient JSON-RPC server becomes extremely simple:
var rpc = require('json-rpc2');
var server = rpc.Server.create();
function add(args, opt, callback) {
callback(null, args[0] + args[1]);
}
server.expose('add', add);
server.listen(8000, 'localhost'); // listen creates an HTTP server
And creating a client to speak to that server is easy too:
var rpc = require('json-rpc2');
var util = require('util');
var client = rpc.Client.create(8000, 'localhost');
client.call('add', [1, 2], function(err, result) {
util.puts('1 + 2 = ' + result);
});
Create a raw (socket) server using:
var rpc = require('json-rpc2');
var server = rpc.Server.create();
server.enableAuth('user', 'pass');
server.listenRaw(8080, 'localhost'); // Listen on socket
Debugging
This module uses the debug package, to debug it, you need to set the Node
environment variable to jsonrpc, either inside your program using program.env.DEBUG='jsonrpc'
or setting it in command line as set DEBUG=jsonrpc
or export DEBUG=jsonrpc
Examples
To learn more, see the examples
directory, peruse test/jsonrpc-test.js
, or
simply "Use The Source, Luke".
More documentation and development is on its way.