# fetchu

> nodejs http-client

Latest version **4.1.3** (published 2021-03-01) · ISC license · 0 weekly downloads

## Install

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

## 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 | 4.1.3 |
| Published | 2021-03-01 |
| First published | 2018-10-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | caub |
| Maintainers | caub |
| Keywords | fetch, node, http, promise |

## Links

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

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

- 4.1.3 (latest) — 2021-03-01
- 4.1.2 — 2020-09-20
- 4.1.1 — 2020-07-29
- 4.1.0 — 2019-06-07
- 4.0.1 — 2019-04-16
- 4.0.0 — 2019-04-04
- 3.2.1 — 2019-03-30
- 3.1.0 — 2019-03-23
- 3.0.0 — 2019-01-19
- 2.0.1 — 2018-11-09
- 2.0.0 — 2018-11-07
- 1.2.1 — 2018-11-06
- 1.2.0 — 2018-11-04
- 1.1.0 — 2018-10-13
- 1.0.3 — 2018-10-13
- … 3 more at https://npm.io/package/fetchu/versions

## README

# fetchu: universal http-client

[![npm version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]

### Differences with fetch:
- automatically handle json body (`JSON.stringify` a body that is an objet literal, and add the right header)
- throws on http error status

### Files:
- fetchu-node.js: using `http`/`https` modules for NodeJS, light drop-in replacement for `node-fetch`
- fetchu-browser.js: it wraps `window.fetch`

```js
import fetchu from 'https://unpkg.com/fetchu';

await fetchu('https://cors-anywhere.herokuapp.com/http://example.com').then(r => r.text()) // <!doctype html><html ...
await fetchu('https://httpbin.org/get?test=foo').then(r => r.json()) // { args: { test: 'foo' }, ...
await fetchu('https://httpbin.org/post', {method: 'POST', body: {test: 'foo'}}).then(r => r.json()) // { args: {},..

// abort:
const ac = new AbortController()
fetchu('https://httpbin.org/get?test=foo', { signal: ac.signal }).then(console.log, console.error)
delay(10).then(() => ac.abort())
```

NodeJS specificities (coming from http/https builtins):
```js
const fetchu = require('fetchu');
await fetchu({ path: '/v1.37/containers/json', socketPath: '/var/run/docker.sock' }).then(r => r.json()) // [ { Id: 'aa6...

// abort:
require('abortcontroller-polyfill/dist/abortcontroller-polyfill-only');
const ac = new AbortController()
fetchu('https://httpbin.org/get?test=foo', { signal: ac.signal }).then(console.log, console.error)
delay(10).then(() => ac.abort());
// or 
const signal = new EventEmitter(); // node.js native events.EventEmitter
fetchu('https://httpbin.org/get?test=foo', { signal }).then(console.log, console.error)
delay(10).then(() => signal.emit('abort'))
```

[npm-image]: https://img.shields.io/npm/v/fetchu.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/fetchu
[travis-image]: https://img.shields.io/travis/caub/fetchu.svg?style=flat-square
[travis-url]: https://travis-ci.org/caub/fetchu

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