HTTP(s) Request
Use as a dependency or copy-paste directly into your code.
Zero-dependency alternative of fetch for NodeJS (with different API).
const { request } = require("@huksley/request");
request("https://jsonip.com").then((res) => {
console.info("Your IP", res.body.ip, "headers", res.headers);
});
ESM
import { request } from "@huksley/request";
const res = await request("https://jsonip.com");
console.info("Your IP", res.body.ip, "headers", res.headers);
Features
- Both CommonJS and ESM environment supported.
- Single-file & gist-sized
- Handles JSON transparently
- Handles binary
- Handles compressed bodies (deflate, brotli, gzip)
- Promise-based
- Default timeout provided