@painsel/quick-fetch
v1.0.5
Published
Zero‑dependency fetch wrapper with timeout, retries, jitter, caching and unified error handling.
Downloads
881
Maintainers
Readme
quick-fetch
Zero‑dependency fetch wrapper with built‑in timeout, retries (exponential back‑off with jitter), optional in‑memory caching, and a unified FetchError.
Installation
npm install @painsel/quick-fetchCurrent version: 1.0.5
Usage
import { qfetch } from 'quick-fetch';
const { request, getJSON, postJSON, getText } = qfetch;
// GET with caching and retries
const data = await getJSON('https://api.example.com/data', { useCache: true, retries: 3 });
// POST JSON payload
const result = await postJSON('https://api.example.com/submit', { name: 'Alice' });
// Plain‑text fetch
const text = await getText('https://example.com/page');API
request(url, options)– Core fetch with timeout, retries, jitter, and caching.getJSON(url, options)– Convenience wrapper returningresponse.json().postJSON(url, payload, options)– POST JSON payload and parse response.getText(url, options)– Returns raw text.FetchError– Custom error exposingurl,response,status, and nativecause.
Features
- Works in browsers and Node ≥ 18 (native
fetch). - No external dependencies – single‑file module.
- Flexible retry condition via
retryConditioncallback. - Optional caching for idempotent GET requests.
License
MIT
