# fetch-curl

> node-libcurl abstraction to api fetch

Latest version **0.5.0** (published 2019-09-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install fetch-curl
pnpm add fetch-curl
yarn add fetch-curl
bun add fetch-curl
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2019-09-23 |
| First published | 2019-09-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 28.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Marcos de Matos |
| Maintainers | mack010 |
| Keywords | node-curl, curl, libcurl, node-libcurl, fetch-curl, fetch-http2 |

## Links

- npm: https://www.npmjs.com/package/fetch-curl
- Repository: https://github.com/marck010/curl-fetch
- Homepage: https://github.com/marck010/curl-fetch#readme
- Issues: https://github.com/marck010/curl-fetch/issues
- npm.io page: https://npm.io/package/fetch-curl

## Dependencies (3)

- [url](https://npm.io/package/url.md) ^0.11.0
- [http-status](https://npm.io/package/http-status.md) ^1.3.2
- [node-libcurl](https://npm.io/package/node-libcurl.md) ^2.0.1

## 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.5.0 (latest) — 2019-09-23
- 0.4.0 (stable) — 2019-09-10
- 0.4.1 — 2019-09-12
- 0.3.7 — 2019-09-09
- 0.3.6 — 2019-09-09
- 0.3.5 — 2019-09-09
- 0.3.4 — 2019-09-09
- 0.3.3 — 2019-09-09
- 0.3.2 — 2019-09-09
- 0.3.1 — 2019-09-09
- 0.3.0 — 2019-09-09
- 0.2.6 — 2019-09-06
- 0.2.5 — 2019-09-06
- 0.2.4 — 2019-09-06
- 0.2.3 — 2019-09-05
- … 11 more at https://npm.io/package/fetch-curl/versions

## README

# fetch-curl

## Motivation

First the difficulty was making http2 requests on node through an http1 proxy. Libcurl abstracts this for us. So why not curl? With this in mind, I decided to create a lib that uses background curl but with the fetch API syntax.

## Installing

To utilize for node.js install the the `npm` module:

```bash
npm i fetch-curl --save
```

## Common Usage

### GET

- Simple GET

```js
const {fetch} = require("fetch-curl");

const res = await fetch('https://restcountries-v1.p.rapidapi.com/all');

const json = res.json();

```

### POST

- Exemple Post with all options

```js
const {fetch, Curl} = require("fetch-curl");

const res = await fetch('https://localhost/post/', {
    method: 'POST',
    body: {
        name: 'foo',
        email: 'foo@foo.com'
    },
    headers: {
        'accept': 'application/json',
        'content-type': 'application/json',
    },
    redirect: "follow",
    follow: 5,
    proxy: 'https://localhost/proxy/',
    timeout: 30000,
    version: 1.1,
    curl: {
        verbose: true,
        opts: {
            [Curl.option.SSL_VERIFYPEER]: false
        }
    }
});

const json = res.json();
```


#### Accessing Headers and other Meta data

```js
const res = await fetch('https://github.com/')
console.log(res.ok);
console.log(res.status);
console.log(res.statusText);
console.log(res.redirected);
console.log(res.url);
console.log(res.countRedirect);
console.log(res.headers.raw());
console.log(res.headers.has('content-type'));
console.log(res.headers.get('content-type'));
```

#### Default Setings

```js
{
    verbose: false,
    method: 'GET',
    folow: 5,
    timeout: 60000,
    version: 1.1,
    redirect: 'follow'
}
```

#### Default Headers

Name              | type             | values
----------------- | -----------------|---------------------------------------
content-length    | number           | automatically calculated

### Options Request

Fetch Standartd Options

Name              | type               | values
------------------- | -----------------|---------------------------------------
body                | object           | object, string
headers             | HeaderInit       | object
method              | string           | GET, POST, PUT, DELETE, HEAD, OPTION, CONNECT
redirect            | RequestRedirect  | folow, manual, error

Fetch Curl Extension Options

Header              | type             | values
------------------- |----------------- |---------------------------------------
follow              | number           | max redirect
timeout             | number           | value in milliseconds
proxy               | string           | url
version             | number           | 1, 1.1, 2
curl                | CurlOptions      |

- Types

HeadersInit

```js
{
  [key: string]: string | number;
}
```

CurlOptions

```js
{
    verbose: boolean,
    opts: {
        [key: string]: string | number | boolean | null;
    }
}
```

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