Proxy any async service through sockets or other transport. Works with promises and subscriptions.
License: MIT License
TypeScript 96.54%JavaScript 3.46%
rpc1's Introduction
rpc1
Proxy any async service through sockets or other transport. Works with promises and subscriptions.
Bindings
Why
Install
Yarn
Example
Local
createBroker(broker=>{// Add a local servicebroker.local('calculator',service=>{service.addMethod('multiply',(x1,x2)=>x1*x2);});// Add a local clientbroker.client(asyncclient=>{constservice=client.use('calculator');try{console.log(awaitservice.multiply(2,3));}catch(err){console.log(err);}});});
Socket
constport=9999;createBroker(broker=>{console.log('Broker is listening');},{plugins: [pluginSocketBroker({
port
})]});// Add a remote servicecreateSocketService('calculator','http://localhost:9999',service=>{service.addMethod('multiply',(x1,x2)=>x1*x2);});// Add a remote clientcreateSocketClient('http://localhost:9999',asyncclient=>{constservice=client.use('local-calculator');try{console.log(awaitservice.multiply(2,3));}catch(err){console.log(err);}});