0.0.4 • Published 8 years ago

consul-gateway v0.0.4

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

Consul Gateway

A consul connected load balancing http client gateway for microservice applications. Loosely based on Martin Fowlers slides on Testing Strategies in a Microservice Architecture .

It uses Consul to get the list of addresses to load balance across and makes requests using the request-promise library. It can also automatically update the address list in the background.

Usage:

const Gateway = require("consul-gateway");

let gateway = null;

Gateway({ service: "name", version: "1.0" })
  .then(_gateway => {
    gateway = _gateway;
  })
  .catch(console.error);

function test() {
  gateway.get("/test", { json: false }) // json is true by default
    .then(response => {
    });
}

Methods:

Gateway({ consul?: object <consul instance>, rpc?: fn() -> promise, name: string, version: string, refreshDelay?: number }) -> Promise<gateway> The version has to be a consul tag that perfectly matches the version string.

gateway.get(endpoint: string, options: request-promise options) -> Promise<any>

gateway.get(endpoint: string, options: request-promise options) -> Promise<any>

gateway.put(endpoint: string, body: any, options: request-promise options) -> Promise<any>

gateway.post(endpoint: string, body: any, options: request-promise options) -> Promise<any>