rpc.io
v1.1.1
Published
rpc over socket.io
Downloads
3
Readme
rpc.io
rpc over socket.io
usage
clientside:
let rpc = require('rpc.io-client')(socket, 2000); # timeout
rpc.call('users.get', {id: 1024}) # Promise
serverside:
io.on('connection', (socket)=> {
rpc = require("rpc.io")(socket);
rpc.register('users.get', (id)=> {nickname: 'foo'});
rpc.register('users', {
delete: function*(id) {
yield db.items.remove({owner: id});
db.users.remove({_id: id});
}
});
});
optional params
rpc.register('projects.create', {description: ''}, (name, description)=>);
socket.register('projects', {
create_defaults: {
description: ''
},
create: (name, description)=>
});
handle all rpc calls
rpc.on("call", (method, kwargs)=> throw Error `method ${method} not implemented`);
handle errors
rpc.on("error", (method, kwargs, error)=> log.error(error));