@frmnt/hydra-to-api

0.0.2 • Public • Published

Hydra to API

The Hydra to API is a service for converting Hydra services methods into http endpoints.

Usage

A single Hydra to API service should be running on each machine using Hydra. By default the Hydra to API binds to port :8421, but you can pass the port you want as well.

$ hydra-to-api
Listening on :8421
^C
$ hydra-to-api 1522
Listening on :1522

After this you can make POST requests to http://localhost:[http port]/[service name]/[method name]

Keep it running in the background with your process manager of choice, e.g. pm2:

$ pm2 start hydra-to-api

Example

Considering the following service:

var hydra = require('@frmnt/hydra');

var hello_service = new hydra.Service('hello', {
    sayHello: function (args, cb) {
        cb(null, 'hello, ' + args.name + '!');
    }
});

You can make a POST request to http://localhost:8421/hello/sayHello passing {name : "Hydra"} as post parameter to receive as response:

hello, Hydra!

Installation

Install the NPM module globally:

$ sudo npm install -g @frmnt/hydra-to-api

Package Sidebar

Install

npm i @frmnt/hydra-to-api

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

2.31 kB

Total Files

3

Last publish

Collaborators