# hyperdirect

> Follow redirects for hyperquest GET requests

Latest version **0.0.0** (published 2013-05-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install hyperdirect
pnpm add hyperdirect
yarn add hyperdirect
bun add hyperdirect
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2013-05-02 |
| First published | 2013-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ForbesLindesay |
| Maintainers | forbeslindesay |

## Links

- npm: https://www.npmjs.com/package/hyperdirect
- Repository: https://github.com/ForbesLindesay/hyperdirect
- npm.io page: https://npm.io/package/hyperdirect

## Dependencies (2)

- [through](https://npm.io/package/through.md) ~2.3.4
- [hyperquest](https://npm.io/package/hyperquest.md) ~0.1.5

## Recent versions

- 0.0.0 (latest) — 2013-05-02

## README

# hyperdirect

Follow redirects for hyperquest GET requests.  Process all other requests exactly as normal.

## Installation

    $ npm install hyperdirect

## Usage

```js
//basic usage
var request = require('hyperquest').request;

request('https://github.com/ForbesLindesay/hyperdirect/archive/master.tar.gz')
  .pipe(require('fs').createWriteStream(__dirname + '/hyperdirect.tar.gz'));

//moderate usage
var request = require('hyperquest')(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](https://github.com/hyperquest/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](https://github.com/hyperquest/hyperquest) or an object of the form `{request: hyperquest}` where `hyperquest` is a function matching the API of [hyperquest](https://github.com/hyperquest/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:

```js
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](https://github.com/hyperquest/hyperquest) but automatically follows up to 10 redirects for GET requests.  It's the same as what you get by calling `hyperdirect()`.

## License

MIT

---
_Source: https://npm.io/package/hyperdirect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
