Remote Procedure Calls overs any EventEmitter transport
JavaScript
Switch branches/tags
Nothing to show
Pull request Compare This branch is 29 commits ahead of monteslu:master.
Latest commit 06bfe4a Aug 29, 2017 @monteslu monteslu websocket example
Permalink
Failed to load latest commit information.
examples/websocket
test
.coveralls.yml
.gitignore
.travis.yml
LICENSE
README.md
client.js
index.js no more client/server only peers Aug 29, 2017
notifier.js
package.json
ws-receive.js no more client/server only peers Aug 29, 2017
ws-send.js

README.md

rawr (a.k.a. RAWRpc)

NPM

Build Status Coverage Status

Remote Procedure Calls (JSON-RPC) sent over any EventEmitter transport.

RAWRpc

Installation

npm install rawr

Using the RPC client

Every rawr client can act as both a client and a server

var rawr = require('rawr');

var client = rawr.init({
  sendEmitter : anEventEmitter,
  sendTopic : 'rpcCall',
  receiveEmitter : anEventEmitter,
  receiveTopic : 'rpcResponse',
  timeout: 5000 // timeout the call after 5 seconds, default is 10
});

// call an rpc method with a parameter and get a promise:
client.rpc('talk', 'luis')
  .then(function(result) {
    console.log(result); // prints 'hello, luis'
  });

A rawr instance acting as an RPC server

var rawr = require('rawr');

var server = rawr.init({
  sendEmitter : anEventEmitter,
  sendTopic : 'rpcResponse', // the opposite of client
  receiveEmitter : anEventEmitter,
  receiveTopic : 'rpcCall' // the opposite of the client
});

function talkToMe(name) {
  // could return a value, a promise, or throw an error
  return 'hello, ' + name;
}

server.addMethod('talk', talkToMe);

Handling Notifications

Both the client and server can send each other notifications:

client.notifications.on('yo', function(who) {
  console.log(who); //prints 'dawg'
});

server.notify('yo', 'dawg');