# roi

> A dependency-free http module.

Latest version **0.18.0** (published 2018-01-11) · Apache-2.0 license · 0 weekly downloads

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.18.0 |
| Published | 2018-01-11 |
| First published | 2016-06-03 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Helio Frota |
| Maintainers | helio-frota, dbevenius, lholmquist, lanceball |
| Keywords | http, promises, node, requests |

## Links

- npm: https://www.npmjs.com/package/roi
- Repository: https://github.com/bucharest-gold/roi
- Homepage: https://github.com/bucharest-gold/roi#readme
- Issues: https://github.com/bucharest-gold/roi/issues
- npm.io page: https://npm.io/package/roi

## 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.18.0 (latest) — 2018-01-11
- 0.17.0 — 2017-12-22
- 0.16.1 — 2017-10-03
- 0.16.0 — 2017-10-02
- 0.15.0 — 2017-03-07
- 0.14.1 — 2016-11-10
- 0.14.0 — 2016-10-26
- 0.13.0 — 2016-10-03
- 0.12.1 — 2016-09-05
- 0.12.0 — 2016-09-02
- 0.11.0 — 2016-08-29
- 0.10.0 — 2016-08-19
- 0.9.0 — 2016-08-02
- 0.8.0 — 2016-08-02
- 0.7.0 — 2016-07-27
- … 8 more at https://npm.io/package/roi/versions

## README

# roi

[![Coverage Status](https://coveralls.io/repos/github/bucharest-gold/roi/badge.svg)](https://coveralls.io/github/bucharest-gold/roi)
[![Build Status](https://travis-ci.org/bucharest-gold/roi.svg?branch=master)](https://travis-ci.org/bucharest-gold/roi)
[![Known Vulnerabilities](https://snyk.io/test/npm/roi/badge.svg)](https://snyk.io/test/npm/roi)
[![dependencies Status](https://david-dm.org/bucharest-gold/roi/status.svg)](https://david-dm.org/bucharest-gold/roi)

[![NPM](https://nodei.co/npm/roi.png)](https://npmjs.org/package/roi)

A dependency-free http module.

## Installation

```
npm install roi -S
```

## Usage

```js
const roi = require('roi');

roi.get('http://localhost:3000/posts')
.then(response => {
  console.log(response);
  console.log(response.statusCode);
  console.log(response.headers);
  console.log(response.body);
})
.catch(e => console.log(e));
```

## More examples

##### POST

```js
const foo = {
  title: 'foo-json',
  author: 'bgold'
};

roi.post('http://localhost:3000/posts', foo)
.then(response => console.log(response)
.catch(e => console.log(e));
```

##### PUT

```js
const foo = {
  title: 'foo-json2',
  author: 'bgold'
};

roi.put('http://localhost:3000/posts/2', foo)
.then(response => console.log(response))
.catch(e => console.log(e));
```

##### DELETE

```js
roi.del('http://localhost:3000/posts/3')
.then(response => console.log(response))
.catch(e => console.log(e));
```

##### HEAD

```js
roi.head('http://localhost:3000/posts/3')
.then(response => console.log(response.statusCode === 200))
.catch(e => console.log(e));
```

##### DOWNLOAD

```js
roi.download('https://github.com/bucharest-gold/roi/raw/master/test/green.png', '/tmp/green.png')
.then(x => console.log(x))
.catch(e => console.log(e));
```

##### UPLOAD

```js
// Fake server side app will save the file called myFileUploaded.png :
const up = (request, response) => {
  request
    .pipe(fs.createWriteStream('/tmp/myFileUploaded.png'))
    .on('finish', () => {
      response.end(request.headers.filename);
    });
};
const server = require('http').createServer(up);
server.listen(3002, () => {});
```

```js
// Upload and check if the uploaded file exists:
roi.upload('http://localhost:3002/', '/tmp/myFile.png')
.then(response => {
  console.log(fs.existsSync('/tmp/myFileUploaded.png'));
});
```

##### Basic authentication

```js
// Add the username and password:
const options = {
  endpoint: 'http://localhost:3000/',
  username: 'admin',
  password: 'admin'
};
roi.get(options)
.then(response => console.log(response))
.catch(e => console.log(e));
```

##### Remove 'Authorization' header

To avoid error like:

`Request header field Authorization is not allowed by Access-Control-Allow-Headers.`

```js
const options = {
  endpoint: 'http://localhost:3000/',
  noAuth: true
};
roi.get(options)
.then(response => console.log(response))
.catch(e => console.log(e));
```


## Contributing

Please read the [contributing guide](./CONTRIBUTING.md)

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