$ npm i egg-jsonrpc-client --save
// {app_root}/config/plugin.js
exports.jsonrpcClient = {
enable: true,
package: 'egg-jsonrpc-client',
};
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.
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 passctx
as the third argument when invoke the method.
MIT License