Skip to content

NewbeeFE/egg-jsonrpc-client

Repository files navigation

egg-jsonrpc-client

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-jsonrpc-client --save

Usage

// {app_root}/config/plugin.js
exports.jsonrpcClient = {
  enable: true,
  package: 'egg-jsonrpc-client',
};

Configuration

Single instance:

exports.jsonrpcClient = {
  client: {
    foo: {
      host: '', // required
      timeout: 5000, // default
      headers: {
        // custom headers
      },
      getHeaders(ctx) {
        return {
          // return custom headers
        }
      },
      beforeRequest(options) {
        // before request hook
      },
    }
  }
};

Multiple instance:

exports.jsonrpcClient = {
  clients: {
    foo: {
      // ...
    },
    bar: {
      // ...
    }
  }
}

see config/config.default.js for more detail.

Example

Single instance:

yield app.jsonrpcClient.invoke('foo.bar', { /** params */ })

Multiple instance:

yield app.jsonrpcClient.get('foo').invoke('foo.bar', {  })

When getHeaders is set, you need to pass ctx as the third argument when invoke the method.

License

MIT License

Releases

No releases published

Packages

No packages published