Jrus
Jrus is a server-client communication utility package, which facilitates seamless remote procedure call.
The communication protocol Jrus uses is jsonrpc 2.0.
Install
npm i jrus
Quick Start
Server side
import { JrusServer, JrusError } from 'jrus';
const server = new JrusServer();
server.register(class Utility {
async time() {
return new Date();
}
async sayHi({ name }) {
return { say: `hello, ${name} ` };
}
async wrong() {
throw new JrusError({ code: 10056, message: 'sample error' });
}
});
server.listen(3000);
Client side
import { JrusClient } from 'jrus';
const client = new JrusClient('http://localhost:3000');
(async () => {
console.log(await client.services.Utility.time());
console.log(await client.services.Utility.sayHi({ name: 'Special Name' }));
try {
await client.services.Utility.wrong();
} catch (e) {
console.error('Error caught: ', e);
}
try {
await client.services.Utility.right();
} catch (e) {
console.error('Error caught: ', e);
}
})();
TODO