Socket
Socket
Sign inDemoInstall

@bifot/json-rpc

Package Overview
Dependencies
43
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @bifot/json-rpc

Solution for communication between services using HTTP protocol via JSON RPC. 🔬


Version published
Weekly downloads
106
decreased by-15.2%
Maintainers
1
Install size
1.87 MB
Created
Weekly downloads
 

Readme

Source

@bifot/json-rpc

Solution for communication between services using HTTP protocol via JSON RPC. 🔬

Install

$ npm i @bifot/json-rpc -S

Usage

Server

const { Server } = require('@bifot/json-rpc');
const { Users } = require('../db');

const server = new Server();

server.use(async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    ctx.error = {
      code: 500,
      message: 'Server error.',
    };
  }
});

server.on('get', async (ctx) => {
  ctx.body = await Users.findOne({
    id: ctx.params.id,
  });
});

server.listen(process.env.APP_PORT);

Client

const { Client } = require('@bifot/json-rpc');

const client = new Client({
  services: {
    users: process.env.USERS_ADDRESS,
  },
});

const user = await client.ask('users.get', {
  id: 10,
}, {
  retries: 5,
  retryDelay: 500,
});

// {
//   error: undefined,
//   result: {
//     id: 10,
//     name: 'Mikhail Semin',
//     age: 16,
//   },
// }

FAQs

Last updated on 18 Jul 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc