request-retry-stream
Request wrapper with retries, focused on streaming
Last updated 9 years ago by ebdrup .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install request-retry-stream 
SYNC missed versions from official npm registry.

request-retry-stream

npm version Build Status Dependency Status devDependency Status Coverage Status

npm install request-retry-stream

Request wrapper with retries, supports streaming. Takes the same options as the request module.

NOTE: only GET http requests are supported when streaming.

There is support for POST, PUT, DELETE and PATCH retrying using callbacks but not streaming (be careful with retrying POST it's not idempotent)

Non-2XX http statusCodes

Non-2XX http statusCodes are returned as errors with the information needed for debugging.

If you want to pass non-2XX error-codes through when streaming use the option passThrough: true

Simple callback usage

var rrs = require('request-retry-stream');
rrs.get({url: 'http://google.com', timeout: 5000}, function(err, resp){
	// handle err and resp. Any response that does not have http status code 2XX is an error here
});

Example of error returned

The error returned in case of non 2XX, has all the options passed to rrs, as well as a statusCode, message, stack, attemptsDone and the body returned for the request.

{
    message: 'Error in request statusCode: 400',
    stack: '...[STACKTRACE]...',
    statusCode: 400,
    url: 'http://example.com',
    attemptsDone: 1,
    method: 'POST'
    body: '...[BODY RETURNED FROM REQUEST]...'
    timeout: 5000
}

Simple stream usage in express middleware with pump

var rrs = require('request-retry-stream');
var pump = require('pump');

function(req, res, next){
	pump(rrs.get('http://google.com', {timeout: 5000}), res, next);
}

Usage in express middleware with pump

var rrs = require('request-retry-stream');
var pump = require('pump');

function(req, res, next){
	var stream = rrs.get({
			url: 'http://google.com',
			attempts: 3, //default
			delay: 500, //default
			timeout: 2000,
			logFunction: console.warn // optional, if you want to be notified about retry
		});	
	pump(stream, res, next);
}

License

MIT

Current Tags

  • 2.1.2                                ...           latest (2 years ago)

26 Versions

  • 2.1.2                                ...           2 years ago
  • 2.1.1                                ...           5 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.0                                ...           8 years ago
  • 1.7.0                                ...           8 years ago
  • 1.6.1                                ...           8 years ago
  • 1.6.0                                ...           8 years ago
  • 1.5.0                                ...           8 years ago
  • 1.4.2                                ...           9 years ago
  • 1.4.1                                ...           9 years ago
  • 1.4.0                                ...           9 years ago
  • 1.3.0                                ...           9 years ago
  • 1.2.1                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.8                                ...           9 years ago
  • 1.1.7                                ...           9 years ago
  • 1.1.6                                ...           9 years ago
  • 1.1.5                                ...           9 years ago
  • 1.1.4                                ...           9 years ago
  • 1.1.3                                ...           9 years ago
  • 1.1.2                                ...           9 years ago
  • 1.1.1                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.2                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (2)
Downloads
Total 23
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (10)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE