# co-request

> co-request promisify wrapper for request

Latest version **1.0.0** (published 2015-08-05) · 0 weekly downloads

## Install

```sh
npm install co-request
pnpm add co-request
yarn add co-request
bun add co-request
```

## 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.0.0 |
| Published | 2015-08-05 |
| First published | 2013-09-09 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 154 |
| Author | Dennis Leukhin |
| Maintainers | leukhin |
| Keywords | request, rest, koa, co, generators |

## Links

- npm: https://www.npmjs.com/package/co-request
- Repository: https://github.com/leukhin/co-request
- Homepage: https://github.com/leukhin/co-request#readme
- Issues: https://github.com/leukhin/co-request/issues
- npm.io page: https://npm.io/package/co-request

## Dependencies (1)

- [request](https://npm.io/package/request.md) *

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2015-08-05
- 0.2.1 — 2015-04-02
- 0.2.0 — 2014-02-04
- 0.1.2 — 2014-02-04
- 0.1.1 — 2013-12-17
- 0.1.0 — 2013-09-09

## README

co-request
==========

Simple wrapper to the request library for co-like interface (node.js generator based code).
You can use it with koa or co

To install simply run:
```bash
npm install co-request
```

Require co first, also it will work on node v0.11.7 and newest only.

You must run node with --harmony flag (--harmony-generators as well)

```bash
node --harmony simple.js
```

Simple example:

```js
"use strict";

let co = require("co");
let request = require("co-request");

co(function* () {
  // You can also pass options object, see http://github.com/mikeal/request docs
    let result = yield request("http://google.com"); 
    let response = result;
    let body = result.body;

    console.log("Response: ", response);
    console.log("Body: ", body);
}).catch(function (err) {
    console.err(err);
});
```

POST example:

```js
"use strict";

co(function* () {
    let result = yield request({
        uri: "http://google.com",
        method: "POST"
    });
})();
```

To pipe request you should use small helper (thanks to [greim](https://github.com/greim)):

```js
function pipeRequest(readable, requestThunk){
  return function(cb){
    readable.pipe(requestThunk(cb));
  }
}

//..and then:

  var value = yield pipeRequest(this.req, request({...}));
```

All methods of request listed in [Request docs](https://github.com/mikeal/request/blob/master/README.md)

##Gratitude##

Thanks for Tj's [Co library](http://github.com/visionmedia/co)

Thanks for Mikeal's [Request library](http://github.com/mikeal/request)

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