egg-jsonrpc-client

1.1.0 • Public • Published

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

/egg-jsonrpc-client/

    Package Sidebar

    Install

    npm i egg-jsonrpc-client

    Weekly Downloads

    0

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • djyde