Git Product home page Git Product logo

reliable-get's Introduction

Reliable HTTP get wrapper (cache and circuit breaker), best wrapped around things you dont trust very much.

Build Status Coverage Status

Basic usage

var ReliableGet = require('reliable-get');
var config = {
  cache:{
    engine:'memorycache'
  },
  circuitbreaker:{
    includePath: true
  }
};
var rg = new ReliableGet();
rg.on('log', function(level, message, data) {
  // Wire up to your favourite logger
});
rg.on('stat', function(type, key, value) {
 // Wire up to your favourite stats library (e.g. statsd)
});
rg.get({url:'http://www.google.com'}, function(err, response) {
   console.log(response.content);
});

Configuration options

When you create an instance of reliable-get you need to specify the cache and circuit breaker behaviour. This then applies across all requests.

var config = {
  cache:{
    engine:'redis',
    url:'redis://localhost:6379?db=0'
  },
  circuitbreaker:{
    windowDuration:5000,
    numBuckets: 5,
    errorThreshold: 20,
    volumeThreshold: 3,
    includePath: true
  }
};
Property Description Example / Default Required
cache.engine Cache to use, redis/memorycache/nocache nocache No
cache.engine.url URL to redis localhost:6379 No
circuitbreaker.windowDuration Window duration to collect errors over 10000 No
circuitbreaker.numBuckets Number of segments within window 10 No
circuitbreaker.errorThreshold Percentage of buckets in error before CB opens 50 No
circuitbreaker.volumeThreshold Number of errored requests before CB opens 10 No

To disable the circuit breaker, simply delete the circuitbreaker configuration.

GET options

When making a get request, you need to provide a basic options object:

rg.get({url:'http://www.google.com'}, function(err, response) {
   console.log(response.content);
});
Property Description Example / Default Required
url Service to get http://my-service.tes.co.uk Yes
timeout Timeout for service 5000 No
cacheKey Key to store cached value against my-service_tes_co_uk No
cacheTTL TTL of cached value 1 minute No
explicitNoCache Do not cache under any circumstances false No
headers Headers to send with request No
tracer Unique value to pass with request No
type Type of request, used for statsd and logging No
statsdKey Key that statsd events will be posted to No
eventHandler Object (see below) for logging and stats No

Example from Compoxure backend request:

var options = {
          url: targetUrl,
          cacheKey: targetCacheKey,
          cacheTTL: targetCacheTTL,
          timeout: utils.timeToMillis(backend.timeout || DEFAULT_LOW_TIMEOUT),
          headers: backendHeaders,
          tracer: req.tracer,
          statsdKey: 'backend_' + utils.urlToCacheKey(host)
};

From compoxure fragment request:

var options = {
      url: url,
      timeout: timeout,
      cacheKey: cacheKey,
      cacheTTL: cacheTTL,
      explicitNoCache: explicitNoCache,
      headers: optionsHeaders,
      tracer: req.tracer,
      statsdKey: statsdKey
  }

reliable-get's People

Contributors

cliftonc avatar doodlemoonch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.