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:
npm i fetch-curl --save
Common Usage
GET
- Simple GET
const fetch = ; const res = await ; const json = res;
POST
- Exemple Post with all options
const fetch Curl = ; const res = await ; const json = res;
Accessing Headers and other Meta data
const res = await console;console;console;console;console;console;console;console;console;
Default Setings
verbose: false method: 'GET' folow: 5 timeout: 60000 version: 11 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
key: string: string | number;
CurlOptions
verbose: boolean opts: key: string: string | number | boolean | null;