# requisition

> ES7 async/await ready http client

Latest version **1.7.0** (published 2016-02-29) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.0 |
| Published | 2016-02-29 |
| First published | 2014-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 15 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 56 |
| Author | Jonathan Ong |
| Maintainers | jongleberry, coderhaoxin |
| Keywords | request, promise, http, https, client |

## Links

- npm: https://www.npmjs.com/package/requisition
- Repository: https://github.com/thenables/requisition
- Homepage: https://github.com/thenables/requisition#readme
- Issues: https://github.com/thenables/requisition/issues
- npm.io page: https://npm.io/package/requisition

## Dependencies (15)

- [mz](https://npm.io/package/mz.md) ^2.1.0
- [fs-cp](https://npm.io/package/fs-cp.md) ^1.2.0
- [cookie](https://npm.io/package/cookie.md) ^0.2.3
- [destroy](https://npm.io/package/destroy.md) ^1.0.3
- [methods](https://npm.io/package/methods.md) ^1.1.0
- [type-is](https://npm.io/package/type-is.md) ^1.5.2
- [statuses](https://npm.io/package/statuses.md) ^1.2.0
- [memorizer](https://npm.io/package/memorizer.md) ^1.0.0
- [temp-path](https://npm.io/package/temp-path.md) ^1.0.0
- [mime-types](https://npm.io/package/mime-types.md) ^2.0.2
- [any-promise](https://npm.io/package/any-promise.md) ^1.1.0
- [http-errors](https://npm.io/package/http-errors.md) ^1.2.7
- [media-typer](https://npm.io/package/media-typer.md) ^0.3.0
- [stream-to-array](https://npm.io/package/stream-to-array.md) ^2.0.2
- [parse-link-header](https://npm.io/package/parse-link-header.md) ^0.4.1

## 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

- 1.7.0 (latest) — 2016-02-29
- 1.6.0 — 2016-02-28
- 1.5.1 — 2015-05-10
- 1.5.0 — 2014-12-19
- 1.4.0 — 2014-12-12
- 1.3.0 — 2014-12-10
- 1.2.0 — 2014-12-07
- 1.1.0 — 2014-10-26
- 1.0.0 — 2014-10-22

## README

# requisition

[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

A light, fluent node.js HTTP client for ES6.
Heavily inspired by [superagent](https://github.com/visionmedia/superagent)
as well as [fetch](https://github.com/github/fetch).
Designed with ES7 async/await in mind.

The API is quite minimal for now.
Features will be added while people request or use them.

```js
var req = require('requisition');

// GET a JSON body
async function () {
  var res = await req('/users.json');
  var body = await res.json();
}

// POST an image file
async function () {
  var res = await req.post('/images.json').sendFile('image.png');
  var body = await res.json();
}
```

## Differences

This is similar to other AJAX libraries like [axios](https://github.com/mzabriskie/axios) except:

- Does not have browser support
- Does not depend on gigantic options objects
- Many utilities for handling HTTP responses like saving to a file

## API

```js
var request = require('requisition');
```

### Request

#### request(url)

`GET` a `url`, return the response object.

#### request\[VERB\](url)

`VERB` a `url`, specifically when it's not `GET`.

#### request().then( response => )

Send the request and wait for the response.

```js
request('/').then(function (response) {

})
```

#### request().set(headers)

Set an object of headers.

#### request().set(header, value)

Set a single header.

#### request().auth(name, pass)

Add basic authorization.

#### request().agent(agent)

Set http agent.

#### request().timeout(ms)

Set timeout.

#### request().redirects(num)

Set max redirect times.

#### request().ifModifiedSince(date)

Set header `If-Modified-Since`.

#### request().ifNoneMatch(value)

Set header `If-None-Match`.

#### request().type(type)

Set header `Content-Type`.

#### request().cookie(key, value, options)

Set cookie, uses [cookie.serialize()](https://github.com/jshttp/cookie)

```js
request('/cookie')
  .cookie(name, value, options)
  .then(function (response) {
    console.info(response.cookies);
  })
```

#### request().query(params)

Add query string.

#### request().send(data)

Add http body.

#### request().sendFile(filename)

Send file.

### Response

#### response.status

The status code of the response.

#### response.headers

The header object of the response.

#### response.is(types...)

Infer the `Content-Type` of the response,
similar to Koa or Express' method.
See [type-is](https://github.com/jshttp/type-is).

#### response.get(header)

Get the value for a header.

#### response.charset

Get charset.

#### response.etag

Get header `ETag`.

#### response.lastModified

Get header `Last-Modified`.

#### response.cookies

Get cookies

```js
request('/cookie').then(function (response) {
  console.info(response.cookies);
})

#### response.buffer().then( buffer => )

Return a single `Buffer` for the entire response.

#### response.text().then( text => )

Return a single `String` for the entire response.

#### response.json().then( body => )

Automatically parse the JSON of the response.

```js
request('/users.json').then(function (response) {
  assert(response.status === 200, 'Bad response!');
  assert(response.is('json'), 'Bad type!');
  return response.json()
}).then(function (body) {
  console.log(body);
})
```

#### response.saveTo([filename]).then( filename => )

Save the response to a file.
If no `filename` is specified,
saves to a random file in your temporary directory.

```js
request('/file.txt').then(function (response) {
  return response.saveTo('/tmp/file.txt');
}).then(function () {
  console.log('file saved!');
})
```

#### response.dump()

Dumps the response. Execute this if you haven't handled the body.

#### response.destroy()

Destroy the response.

[npm-image]: https://img.shields.io/npm/v/requisition.svg?style=flat-square
[npm-url]: https://npmjs.org/package/requisition
[github-tag]: http://img.shields.io/github/tag/thenables/requisition.svg?style=flat-square
[github-url]: https://github.com/thenables/requisition/tags
[travis-image]: https://img.shields.io/travis/thenables/requisition.svg?style=flat-square
[travis-url]: https://travis-ci.org/thenables/requisition
[coveralls-image]: https://img.shields.io/coveralls/thenables/requisition.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/thenables/requisition
[david-image]: http://img.shields.io/david/thenables/requisition.svg?style=flat-square
[david-url]: https://david-dm.org/thenables/requisition
[license-image]: http://img.shields.io/npm/l/requisition.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/requisition.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/requisition

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