gentle-http
v0.1.14
Published
HTTP client for Node.js with built-in per-host rate limiting and response caching, powered by a Rust native addon.
Readme
gentle-http
HTTP client for Node.js with built-in per-host rate limiting and response caching, powered by a Rust native addon.
Install
npm install gentle-httpUsage
import { sendRequest } from "gentle-http";
const response = await sendRequest({
method: "GET",
url: "https://api.example.com/data",
});
// response is a structured object:
// {
// status: 200,
// statusText: "OK",
// headers: { "content-type": "application/json", ... },
// body: "...",
// cached: false,
// }
console.log(response.status); // 200
console.log(response.body); // response body as a stringPOST with headers and body
const response = await sendRequest({
method: "POST",
url: "https://api.example.com/data",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "world" }),
});
const data = JSON.parse(response.body);Custom configuration
Call configure before any requests to override defaults:
import { configure } from "gentle-http";
configure({
timeoutMs: 10_000, // request timeout (default: 30000)
hostRateLimit: 10, // per-host requests per second (default: 5)
hostConcurrency: 20, // per-host concurrent request limit (default: 10)
cacheTtlSecs: 60, // cache time-to-live (default: 300)
cacheCapacity: 500, // max cached responses (default: 1000)
});