# @everymundo/promise-data-to

> This is a helper to perform POST requests using promises and no external dependencies

Latest version **3.0.3** (published 2020-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @everymundo/promise-data-to
pnpm add @everymundo/promise-data-to
yarn add @everymundo/promise-data-to
bun add @everymundo/promise-data-to
```

## 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 | 3.0.3 |
| Published | 2020-03-20 |
| First published | 2018-01-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel Santana |
| Maintainers | alexandprivate, anahiem, avivero93, ballester, caviola, christopherepm, danielsan, davidxl, dcuevacem, devrchancay, eduardomundo, emdavidmoreno, erlin, ernestocarrasco, everymundo-admin, front10devs, gallegogt, hdelcastillo, herlin, hugopalomares, hveitia, jonmorazav, joseivansandoya, karinfdez, kseniakirilyuk, mvcruzata, neilgoldman, ortega.dc98, pedroleon917, raydel, raydel.miranda, raymer, rodneyem, yartiles |
| Keywords | nodejs, node, http, https, request |

## Links

- npm: https://www.npmjs.com/package/@everymundo/promise-data-to
- Repository: https://github.com/EveryMundo/promise-data-to
- Homepage: https://github.com/EveryMundo/promise-data-to#readme
- Issues: https://github.com/EveryMundo/promise-data-to/issues
- npm.io page: https://npm.io/package/@everymundo/promise-data-to

## Dependencies (1)

- [@everymundo/simple-logr](https://npm.io/package/@everymundo/simple-logr.md) ^2.2.2

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

- 3.0.3 (latest) — 2020-03-20
- 3.0.2 — 2020-03-19
- 3.0.1 — 2020-03-19
- 3.0.0 — 2020-03-16
- 2.0.3 — 2020-03-06
- 1.4.2 — 2020-03-05
- 1.4.1 — 2020-02-28
- 2.0.2 — 2020-02-18
- 2.0.1 — 2020-02-18
- 2.0.0 — 2020-02-18
- 1.4.0 — 2019-10-22
- 1.3.1 — 2019-08-08
- 1.3.0 — 2019-06-04
- 1.2.3 — 2019-05-28
- 1.2.2 — 2019-05-28
- … 15 more at https://npm.io/package/@everymundo/promise-data-to/versions

## README

# promise-data-to
This is a helper to perform POST requests using promises.

## Install
```sh
npm install @everymundo/promise-data-to
```

## Usage
### POST some data
```js
const httpClient = require('@everymundo/promise-data-to')

const headers = { 'content-type': 'application/json' }
const endpoint = new httpClient.PostEndpoint('http://your-host.com/path', headers)
const data = { myData:'Something' }

const res = await httpClient.promiseDataTo(endpoint, data)
```

### GET some data
```js
const httpClient = require('@everymundo/promise-data-to')

const headers = { 'authorization': 'your token' }
const endpoint = new httpClient.GetEndpoint('http://your-host.com/path', headers)

const res = await httpClient.promiseGet(endpoint)
```

### POST using the Fetch API
```js
const httpClient = require('@everymundo/promise-data-to')

const headers = { 'authorization': 'your token' }
const res = await httpClient.fetch('http://your-host.com/path', { headers, body: data })
```

### GET using the Fetch API
```js
const { fetch } = require('@everymundo/promise-data-to')

const headers = { 'authorization': 'your token' }
const res = await fetch('http://your-host.com/path', { headers })
```

## Response Schema
```js
{
    statusCode, // the response statusCode
    code, // alias for statusCode [for backaward compatibility]
    start, // Date Object captured right before starting the request
    end: Date.now(), // Int Timestamp from when the request has finished
    attempt, // the number of attempts of the retries
    endpoint, // the endpoint object either passed or generated from a string
    resTxt, // alias for responseText [for backaward compatibility]
    responseText, // the response buffer.toString()
    buffer, // raw response buffer
    dataType, // the name of the constructor of the posted data [Array, Object, String, Buffer]
    dataLen, // when posting arrays it shows the number of array items posted
    compress, // the type of compression for the POST request, if any. Valid values are gzip and deflate
    requestHeaders, // the headers used on the request
    responseHeaders // the headers received from the remote server
}
```

## Some Features
* Automatically retries to send the requests when statusCode > 399

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