2.8.1 • Published 3 years ago

proxy.rpc v2.8.1

Weekly downloads
8
License
ISC
Repository
github
Last release
3 years ago

Proxy.rpc

Install

npm i --save proxy.rpc 

Run

#ctrl.js#
module.exports = {
   a() {
       
   },
   b: {
     c(x, y) {
       return x + y
     }
   },
   d: {
     e: {
       f({x, y}) {
         return x * y
       }
     }
   }
 };
#index.js#
const ctrl = require('./ctrl');
let serverPromise = require('proxy.rpc').run(ctrl, {
  username: process.env.SERVICE_USERNAME,   // optional
  password: process.env.SERVICE_PASSWORD,   // optional
  port: process.env.SERVICE_PORT            // optional, default 8080
  logger: {info, error}                     // optional
  ctx: <String>                             // optional for logger context
});
//if need to stop
serverPromise.then(s => s.close())

Connection at remote service

REMOTE_SERVICE_URL should be represented as 
http[s]://[username:password@]host[:port]
const remoteService = require('proxy.rpc').at(REMOTE_SERVICE_URL, {logger, ctx});  
await remoteService.a();
await remoteService.b.c(1, 2);
await remoteService.d.e.f({x:1, y:2});

Raw RPC request/response examples

_Request_
{ path: 'a',
  data: [] }
  
_Response_
{__result: 'ok'} //if method returns undefined, proxy returns 'ok' 
_Request_
{ path: 'b.c', // OR ['b', 'c']
  data: [ 1, 2 ] }
  
_Response_
{__result: 3}
2.8.1

3 years ago

2.8.0

3 years ago

2.7.2

3 years ago

2.7.1

3 years ago

2.7.0

3 years ago

2.6.2

3 years ago

2.6.1

3 years ago

2.6.0

3 years ago

2.5.1

3 years ago

2.4.2

3 years ago

2.4.1

3 years ago

2.4.0

3 years ago

2.3.2

3 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.6

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago