# http-conn

> Small lib HTTP client for the browser, Promise based and cancelable.

Latest version **1.0.9** (published 2021-11-19) · 0 weekly downloads

## Install

```sh
npm install http-conn
pnpm add http-conn
yarn add http-conn
bun add http-conn
```

## 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.9 |
| Published | 2021-11-19 |
| First published | 2021-10-23 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | devrrnogueira |
| Keywords | http, https, axios, request, ajax, connector, fetch, download, cancelable, small, browser |

## Links

- npm: https://www.npmjs.com/package/http-conn
- Repository: https://github.com/devrrnogueira/http-conn
- Homepage: https://github.com/devrrnogueira/http-conn#readme
- Issues: https://github.com/devrrnogueira/http-conn/issues
- npm.io page: https://npm.io/package/http-conn

## 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.0.9 (latest) — 2021-11-19
- 1.0.8 — 2021-11-19
- 1.0.7 — 2021-11-18
- 1.0.6 — 2021-11-10
- 1.0.5 — 2021-11-07
- 1.0.4 — 2021-11-04
- 1.0.3 — 2021-11-04
- 1.0.2 — 2021-11-04
- 1.0.1 — 2021-10-23
- 1.0.0 — 2021-10-23

## README

# http-conn
Small lib HTTP client for the browser, Promise based and cancelable.

## Install
```
npm install http-conn
```

### Usage
``` javascript
import HttpConnector from 'http-conn'

const http = new HttpConnector({ 
    // [optional] set default timeout of request, in milliseconds
    timeout: 5000,

    // [optional] set default headers
    headers: {},

    // [optional] middleware from request
    onRequest(config) {
        config.headers.Authorization = 'mytoken'
    },

    // [optional] middleware from response
    onResponse(response) {
        let newResponse = {
            ...response,
            outher: true
        }

        return newResponse
    },

    // [optional] middleware from error
    onError(error) {
        console.log(error)
    }
})

// Basic request
http.get('http://httpbin.org/get?arg=one')
    .then(result => {
        console.log(result)
    })
    .catch(error => {
        console.error(error)
    })

http.post('http://httpbin.org/post', { field: 'value' })
    .then(result => {
        console.log(result)
    })

// Custom timeout
await http.get('http://httpbin.org/get', {timeout: 10000})

// Using cache
await http.get('http://httpbin.org/get', {cache: 60000}) // one minutes of cache

// Cancelable request
let { request, cancel } = http.get('http://172.164.102.88/', null, true)

request.catch(error => {
    console.log(error)
})

// Download
await http.get('http://httpbin.org/image/jpeg', {download: 'filename'})

setTimeout(cancel, 3000)

```

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