Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reliable-get

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reliable-get

A circuit breaker and cached wrapper for GET requests (enables reliable external service interaction).

  • 0.1.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20
increased by233.33%
Maintainers
1
Weekly downloads
 
Created
Source

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
  }
};
PropertyDescriptionExample / DefaultRequired
cache.engineCache to use, redis/memorycache/nocachenocacheNo
cache.engine.urlURL to redislocalhost:6379No
circuitbreaker.windowDurationWindow duration to collect errors over10000No
circuitbreaker.numBucketsNumber of segments within window10No
circuitbreaker.errorThresholdPercentage of buckets in error before CB opens50No
circuitbreaker.volumeThresholdNumber of errored requests before CB opens10No

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);
});
PropertyDescriptionExample / DefaultRequired
urlService to gethttp://my-service.tes.co.ukYes
timeoutTimeout for service5000No
cacheKeyKey to store cached value againstmy-service_tes_co_ukNo
cacheTTLTTL of cached value1 minuteNo
explicitNoCacheDo not cache under any circumstancesfalseNo
headersHeaders to send with requestNo
tracerUnique value to pass with requestNo
typeType of request, used for statsd and loggingNo
statsdKeyKey that statsd events will be posted toNo
eventHandlerObject (see below) for logging and statsNo

Example from a 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 a compoxure fragment request:

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

Keywords

FAQs

Package last updated on 12 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc