# req-then

> Simple http(s) request function, returning a promise.

Latest version **0.6.4** (published 2017-06-29) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install req-then
pnpm add req-then
yarn add req-then
bun add req-then
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.6.4 |
| Published | 2017-06-29 |
| First published | 2015-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Lloyd Brookes |
| Maintainers | 75lb |
| Keywords | http, https, request, promise, then, req, es6, native |

## Links

- npm: https://www.npmjs.com/package/req-then
- Repository: https://github.com/75lb/req-then
- Homepage: https://github.com/75lb/req-then#readme
- Issues: https://github.com/75lb/req-then/issues
- npm.io page: https://npm.io/package/req-then

## Dependencies (5)

- [typical](https://npm.io/package/typical.md) ^2.6.1
- [array-back](https://npm.io/package/array-back.md) ^2.0.0
- [lodash.pick](https://npm.io/package/lodash.pick.md) ^4.4.0
- [defer-promise](https://npm.io/package/defer-promise.md) ^1.0.1
- [stream-read-all](https://npm.io/package/stream-read-all.md) ^0.1.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.6.4 (latest) — 2017-06-29
- 0.6.3 — 2017-06-29
- 0.6.2 — 2017-06-18
- 0.6.1 — 2017-02-18
- 0.6.0 — 2017-02-18
- 0.5.1 — 2016-11-01
- 0.5.0 — 2016-09-19
- 0.4.1 — 2016-08-23
- 0.4.0 — 2016-08-23
- 0.3.4 — 2016-08-07
- 0.3.3 — 2016-07-14
- 0.3.2 — 2016-07-14
- 0.3.1 — 2016-07-14
- 0.3.0 — 2016-07-14
- 0.2.4 — 2015-11-25
- … 4 more at https://npm.io/package/req-then/versions

## README

[![view on npm](http://img.shields.io/npm/v/req-then.svg)](https://www.npmjs.org/package/req-then)
[![npm module downloads](http://img.shields.io/npm/dt/req-then.svg)](https://www.npmjs.org/package/req-then)
[![Dependency Status](https://david-dm.org/75lb/req-then.svg)](https://david-dm.org/75lb/req-then)
[![Coverage Status](https://coveralls.io/repos/github/75lb/req-then/badge.svg)](https://coveralls.io/github/75lb/req-then)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)

<a name="module_req-then"></a>

## req-then
Wraps node's built-in http(s) `request` function with a few extras:

- Returns a promise, resolving to an object containing the data, node response and original request.
- Automatically selects `http` or `https` transport depending on the input URL.
- Cancellable (which `fetch` is not).

**Example**  
```js
const request = require('req-then')

request('http://www.bbc.co.uk')
  .then(response => {
    console.log('Response data received', response.data)
    console.log('The original request options', response.req)
    console.log('The nodejs response instance', response.res)
  })
  .catch(console.error)
```
**Example**  
```js
const request = require('req-then')
const url = require('url')
const reqOptions = url.parse('http://www.bbc.co.uk')
const controller = {}
reqOptions.controller = controller
request(reqOptions)
  .then(response => {
    console.log('Response data received', response.data)
  })

// kill the request and close the socket
controller.abort()
```
<a name="exp_module_req-then--request"></a>

### request(reqOptions, [data]) ⇒ <code>external:Promise</code> ⏏
Returns a promise for the response.

**Kind**: Exported function  
**Resolve**: <code>object</code> - `res` will be the node response object, `data` will be the data, `req` the original request.  
**Reject**: <code>Error</code> - If aborted, the `name` property of the error will be `aborted`.  

| Param | Type | Description |
| --- | --- | --- |
| reqOptions | <code>string</code> \| <code>object</code> | Target url string or a standard node.js http request options object. |
| [reqOptions.controller] | <code>object</code> | If supplied, an `.abort()` method will be created on it which, if invoked, will cancel the request. Cancelling will cause the returned promise to reject with an `'aborted'` error. |
| [data] | <code>\*</code> | Data to send with the request. |


* * *

&copy; 2015-17 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).

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