# requests

> An streaming XHR abstraction that works in browsers and node.js

Latest version **0.3.0** (published 2019-08-06) · MIT license · 0 weekly downloads

## Install

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

## 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.3.0 |
| Published | 2019-08-06 |
| First published | 2014-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 2.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Arnout Kazemier |
| Maintainers | 3rdeden, swaagie |
| Keywords | request, xhr, requests, http, xml, xmlhttp, xmlhttprequest |

## Links

- npm: https://www.npmjs.com/package/requests
- Repository: https://github.com/unshiftio/requests
- Issues: https://github.com/unshiftio/requests/issues
- npm.io page: https://npm.io/package/requests

## Dependencies (7)

- [axo](https://npm.io/package/axo.md) 0.0.x
- [hang](https://npm.io/package/hang.md) 1.0.x
- [loads](https://npm.io/package/loads.md) 0.0.x
- [xhr-send](https://npm.io/package/xhr-send.md) 1.0.x
- [extendible](https://npm.io/package/extendible.md) 0.1.x
- [eventemitter3](https://npm.io/package/eventemitter3.md) ~4.0.0
- [node-http-xhr](https://npm.io/package/node-http-xhr.md) ~1.3.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2019-08-06
- 0.2.2 — 2017-06-13
- 0.2.1 — 2017-06-13
- 0.2.0 — 2017-06-08
- 0.1.7 — 2015-09-17
- 0.1.6 — 2015-05-28
- 0.1.5 — 2015-05-18
- 0.1.4 — 2015-05-12
- 0.1.3 — 2015-05-12
- 0.1.2 — 2015-05-06
- 0.1.1 — 2015-04-07
- 0.1.0 — 2015-04-07
- 0.0.1 — 2014-03-29

## README

# requests

[![Made by unshift][made-by]](http://unshift.io)[![Version npm][version]](http://browsenpm.org/package/requests)[![Build Status][build]](https://travis-ci.org/unshiftio/requests)[![Dependencies][david]](https://david-dm.org/unshiftio/requests)[![Coverage Status][cover]](https://coveralls.io/r/unshiftio/requests?branch=master)[![IRC channel][irc]](http://webchat.freenode.net/?channels=unshift)

[made-by]: https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square
[version]: https://img.shields.io/npm/v/requests.svg?style=flat-square
[build]: https://img.shields.io/travis/unshiftio/requests/master.svg?style=flat-square
[david]: https://img.shields.io/david/unshiftio/requests.svg?style=flat-square
[cover]: https://img.shields.io/coveralls/unshiftio/requests/master.svg?style=flat-square
[irc]: https://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square

Requests is a small library that implements fully and true streaming XHR for
browsers that support these methods. It uses a variety of proprietary
`responseType` properties to force a streaming connection, even for binary data.
For browsers that don't support this we will simply fallback to a regular but
**async** XHR 1/2 request or ActiveXObject in even older deprecated browsers.

- Internet Explorer >= 10: `ms-stream`
- FireFox >= 9: `moz-chunked`
- FireFox < 20: `multipart`

This module comes with build-in protection against ActiveX blocking that is
frequently used in firewalls & virus scanners.

## Installation

The module is released in the public npm registry and can be installed using:

```
npm install --save requests
```

## Usage

The API is a mix between the Fetch API, mixed with EventEmitter API for the
event handling.

```js
'use strict';

var requests = require('requests');
```

Now that we've included the library we can start making requests. The exported
method accepts 2 arguments:

- **url** Required URL that you want to have requested.
- **options** Optional object with additional configuration options:
  - **streaming** Should we use streaming API's to fetch the data, defaults to
  `false`.
  - **method** The HTTP method that should be used to get the contents, defaults
  to `GET`.
  - **mode** The request mode, defaults to `cors`
  - **headers** Object with header name/value that we need to send to the server.
  - **timeout** The timeout in ms before we should abort the request.
  - **manual** Manually `open` the request, defaults to `false`.

```js
requests('https://google.com/foo/bar', { streaming })
.on('data', function (chunk) {
  console.log(chunk)
})
.on('end', function (err) {
  if (err) return console.log('connection closed due to errors', err);

  console.log('end');
});
```

## Events

In the example above you can see the that we're listing to various of events.
The following events are emitted:

- `data` A new chunk of data has been received. It can be a small chunk but also
  the full response depending on the environment it's loaded in.
- `destroy` The request instance has been fully destroyed.
- `error` An error occurred while requesting the given URL.
- `end` Done with requesting the URL. An error argument can be supplied if the
  connection was closed due to an error.
- `before` Emitted before we send the actual request.
- `send` Emitted after we've succesfully started the sending of the data.

### requests#destroy

Destroy the running XHR request and release all the references that the
`requests` instance holds. It returns a boolean as indication of a successful
destruction.

```js
requests.destroy();
```

### Requests.requested

The total amount of requests that we've made in this library. It also serves as
unique id for each request that we store in `.active`.

### Requests.active

An object that contains all running and active requests. Namespaced under
`request.requested` id and the requests instance.

## License

MIT

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