Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jrus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jrus

Jrus is a server-client communication utility package, which facilitates **seamless** remote procedure call.

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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';

// create a new server instance
const server = new JrusServer();

// register a service
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' });
  }
});

// run and listen on port 3000
server.listen(3000);

Client side

import { JrusClient } from 'jrus';

// create a client and connect http://localhost:3000
const client = new JrusClient('http://localhost:3000');

(async () => {
  // remote procedure call: Utility.time
  console.log(await client.services.Utility.time());
  // 018-03-31T15:54:37.568Z

  // remote procedure call: Utility.sayHi, with parameters { name: 'Special Name' }
  console.log(await client.services.Utility.sayHi({ name: 'Special Name' }));
  // { say: 'hello, Special Name ' }

  // remote procedure call: Utility.wrong; and cathc error thrown on the server side
  try {
    await client.services.Utility.wrong();
  } catch (e) {
    console.error('Error caught: ', e);
    // Error caught:  JrusError { code: 10056, message: 'sample error' }
  }

  // call some function nonexist: Utility.right
  try {
    await client.services.Utility.right();
  } catch (e) {
    console.error('Error caught: ', e);
    // Error caught:  JrusError { code: -32601, message: 'Method not found' }
  }
})();

TODO

FAQs

Package last updated on 11 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc