Registry / devops / wonderful-fetch

wonderful-fetch

JSON →
library2.0.5jsnpmunverified

A powerful wrapper around the native fetch API that works in both Node.js (>=18) and browser environments. Current stable version is 2.0.5, released actively by ITW Creative Works. Key differentiators include automatic JSON response parsing, retries with exponential backoff, request timeouts via AbortController, authorization header management (auto-prefixes 'Bearer '), query parameter building, cache busting, file downloads (Node.js only), and enriched error objects with HTTP status codes. Designed to simplify common fetch patterns while retaining full flexibility.

npm install wonderful-fetch
INSTALL
IMPORT
SIG · WONDERFUL-FETCH
W
wonderful-fetch
devopsjavascriptv2.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (fetch)
import fetch from 'wonderful-fetch'
import { fetch } from 'wonderful-fetch'
The package exports a single default export, not a named export.
CommonJS require
const fetch = require('wonderful-fetch')
const { fetch } = require('wonderful-fetch')
CommonJS users must require the default export.
CDN global
<script src="https://cdn.jsdelivr.net/npm/wonderful-fetch@latest/dist/wonderful-fetch.min.js"></script> WonderfulFetch('https://api.example.com/data', { response: 'json' })
fetch('https://api.example.com/data') // undefined in global scope
CDN exposes WonderfulFetch as a global function, not fetch.

Shows a basic GET request with JSON response, retries, timeout, and authorization header.

import fetch from 'wonderful-fetch'; async function main() { try { const data = await fetch('https://httpbin.org/json', { method: 'get', response: 'json', tries: 3, timeout: 10000, authorization: process.env.API_KEY ?? '', }); console.log('Data:', data); } catch (err) { console.error('Error:', err.message, 'Status:', err.status); } } main();
Debug
Known issues
breakingVersion 2.x dropped support for Node.js <18.
fix
Upgrade Node.js to >=18 or use wonderful-fetch@1.x.
affects: >=2.0.0
deprecatedThe 'output' option with value 'complete' is deprecated. Use separate properties or a dedicated response type.
fix
Access status, headers, and body individually or use a newer API pattern.
affects: >=2.0.0
gotchaAuthorization auto-prefixes 'Bearer ' if no scheme is provided. If you want a custom scheme (e.g., 'Basic'), include it explicitly.
fix
Pass authorization as 'Basic abc123' to avoid unwanted 'Bearer ' prefix.
affects: >=1.0.0
gotchaRequest body objects are automatically JSON-stringified. To send a non-JSON body (e.g., FormData), pass it as-is.
fix
For FormData or other body types, do not wrap in an object that triggers JSON serialization.
affects: >=1.0.0
gotchaThe 'download' option only works in Node.js. Using it in a browser will throw an error.
fix
Guard file downloads with environment detection: if (typeof window === 'undefined') { /* download */ }
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught ReferenceError: fetch is not defined
Using a named import instead of default import (import { fetch } from 'wonderful-fetch').
fix
Use import fetch from 'wonderful-fetch' (default import).
TypeError: Failed to parse URL from undefined
Calling fetch() without a URL argument.
fix
Pass a valid URL string as the first argument.
Error: Request failed with status 404
Server returned a non-2xx response. The error includes the response body.
fix
Check the URL or handle the error with try/catch and inspect err.status.
Error: download is not supported in the browser
Using the 'download' option in a browser environment.
fix
Only use 'download' in Node.js, or wrap with environment check.
Upgrade
Version history
2.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
wonderful-fetch — npm install wonderful-fetch · libregistry