0.0.2 • Published 6 years ago

@frmnt/hydra-to-api v0.0.2

Weekly downloads
3
License
MIT
Repository
-
Last release
6 years ago

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