2.0.3 • Published 5 years ago

prxy v2.0.3

Weekly downloads
11
License
ISC
Repository
gitlab
Last release
5 years ago

prxy

Client/Server wrapper for simple modules with top level functions that return promises or streams.

API

serve(modules, options)

Start an http server proxy for the given module.

  • modules - the module to proxy. The top level async functions (that return promises or streams) will be proxied. To proxy multiple modules, pass an array of objects with key api specifying the module and ns specifying the namespace (omit to use default namespace).
  • options - server options
    • port - port to listen on

load(options)

Configure how to communicate with a remote service.

  • options - client options
    • url - The url to access the remote serivce (e.g. http://remotehost:1234)
    • ns - The namespace associated with the service (omit to use default)
    • local - Alternative to load a local module directly (absolute file path or module from package.json)

Usage

Server

const Prxy = require('prxy');

const math = {
   add: async (a, b) => {

       return a + b;
   }
}

Prxy.serve(math, { port: 3000 });

Client

const Prxy = require('prxy');
const MathService = Prxy.load({ url: 'http://localhost:3000' });
const result = await MathService.add(1, 1);
console.log('1 + 1 =', result);
2.0.3

5 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago