Giter Club home page Giter Club logo

hyperdirect's Introduction

hyperdirect

Follow redirects for hyperquest GET requests. Process all other requests exactly as normal.

Installation

$ npm install hyperdirect

Usage

//basic usage
var request = require('hyperdirect').request;

request('https://github.com/ForbesLindesay/hyperdirect/archive/master.tar.gz')
  .pipe(require('fs').createWriteStream(__dirname + '/hyperdirect.tar.gz'));

//moderate usage
var request = require('hyperdirect')(2/* Max Redirects to follow, defaults to 10 */);

request('https://github.com/ForbesLindesay/hyperdirect/archive/master.tar.gz')
  .pipe(require('fs').createWriteStream(__dirname + '/hyperdirect.tar.gz'));

//advanced usage
var hyperdirect = require('hyperdirect')(5, require('hyperquest'));

API

hyperdirect(maxRedirects, subquest)

Returns a new function with the same API as hyperquest but which follows redirects for GET requests. Both maxRedirects and subquest are optional and can be in either order.

If provided, subquest should be a function which matches the API of hyperquest or an object of the form {request: hyperquest} where hyperquest is a function matching the API of hyperquest.

maxRedirects will default to 10. Once the request has been redirected more times than that it will give up and throw an error. The error has a res and statusCode property set to the apropriate properties from the last request made.

The returned stream will emit redirect events with the response of any request that results in another redirect. This means you could trace the path something a request took by doing:

require('hyperdirect')(100)(url)
  .on('redirect', function (res) {
    console.log('REDIRECT ' + res.statusCode + ': ' + res.headers.location);
  })
  .on('response', function (res) {
    console.log('FINAL URL: ' + res.url);
  });

hyperdirect.request(uri, opts, cb)

Follows exactly the same API as hyperquest but automatically follows up to 10 redirects for GET requests. It's the same as what you get by calling hyperdirect().

License

MIT

hyperdirect's People

Contributors

forbeslindesay avatar leesei avatar

Watchers

Lluís Ulzurrun de Asanza Sàez avatar James Cloos avatar Vigmore avatar Álvaro Ponce Arévalo avatar Javier Rodríguez Vidal 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.