loke-http-rpc

2.0.0 • Public • Published

loke-http-rpc

const lokeHttpRpc = require('loke-http-rpc');
 
const myService = {
  doStuff() {
    return Promise.resolve('stuff done');
  }
};
 
const MY_SERVICE_META = {
  service: 'my-service', // display name
  multiArg: false, // defaults to false. If true accepts an array for arguments, if false an array will be assumed to be the first (and only) argument.
  expose: [  // The methods to be exposed publically
    'doStuff'
  ]
};
 
const myRpcService = lokeHttpRpc.createRequestHandler(myService, MY_SERVICE_META);
 
app.use('/rpc', myRpcService);

Then, if running on port 5000:

curl -X POST http://localhost:5000/rpc/doStuff

Also, to list runtime RPC metadata you can GET /rpc

curl -X GET http://localhost:5000/rpc

Readme

Keywords

none

Package Sidebar

Install

npm i loke-http-rpc

Weekly Downloads

5

Version

2.0.0

License

none

Last publish

Collaborators

  • loke