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.
create
✓ import { create } from 'fetch-fun'
✗ import fetchFun from 'fetch-fun'
This library exports only named exports; there is no default export.
baseUrl
✓ import { baseUrl } from 'fetch-fun'
✗ const { baseUrl } = require('fetch-fun');
The library is ESM-only; CommonJS require is not supported.
fetchJSON
✓ import { fetchJSON } from 'fetch-fun'
Also available as part of wildcard import: import * as ff from 'fetch-fun'. fetchJSON is a pipeable operation, not a standalone function.
header
✓ import { header } from 'fetch-fun'
✗ import { headers } from 'fetch-fun'
The export is named `header` (singular), not `headers`. It adds a single header.
retry
✓ import { retry } from 'fetch-fun'
✗ import { retry } from 'fetch-fun/retry'
All exports are at the package root; there are no subpath exports.
Creates a reusable HTTP client with base URL and headers, then makes GET and POST requests with retry and timeout using the pipe API.
import * as ff from 'fetch-fun';
const client = ff.create()
.pipe(ff.baseUrl, 'https://api.example.com')
.pipe(ff.header, 'Content-Type', 'application/json');
const users = await client
.pipe(ff.url, '/users')
.pipe(ff.fetchJSON);
const newUser = await client
.pipe(ff.url, '/users')
.pipe(ff.method, 'POST')
.pipe(ff.jsonBody, { name: 'John', email: 'john@example.com' })
.pipe(ff.fetchJSON);
const data = await client
.pipe(ff.url, '/data')
.pipe(ff.retry, 3)
.pipe(ff.signal, AbortSignal.timeout(5000))
.pipe(ff.fetchJSON);
console.log(users, newUser, data);
Debug
Known issues
breakingThe initial version v0.1.0 had a different API with builder pattern. Updated to pipe-based API in v0.2.0.fixMigrate from builder pattern to pipe pattern using .pipe() calls.
affects: 0.1.x
gotchafetchJSON pipes the response through response.json() and does not include response status validation; you must handle non-2xx responses manually.fixUse .pipe(ff.fetch) and check response.ok before calling .json() on the response, or use a custom validation pipe.
affects: >=0.2.0
gotchaThe `signal` pipe expects an AbortSignal, not a timeout number; you must explicitly create AbortSignal.timeout or AbortController.fixUse .pipe(ff.signal, AbortSignal.timeout(ms)) instead of passing a number.
affects: >=0.2.0
deprecatedThe `pipe` method replaces the earlier `.use()` method from v0.2.0-beta.1. The `.use()` method is still present but deprecated.fixReplace .use(...) calls with .pipe(...).
affects: >=0.2.0-beta.1 <0.3.0
gotchaThe library does not provide any default error handling for network failures; fetchJSON will reject on network errors but not on HTTP error statuses.fixAdd a custom error handling pipe after fetchJSON to check response status and throw if needed.
affects: >=0.2.0
Errors
Common errors & fixes
TypeError: ff.create is not a function
Incorrect import: using default import instead of named import.
fixUse import * as ff from 'fetch-fun' or import { create } from 'fetch-fun'. Error: Module not found: Can't resolve 'fetch-fun'
Package not installed or missing from package.json.
fixRun npm install fetch-fun or pnpm add fetch-fun.
Uncaught TypeError: Failed to execute 'json' on 'Response': body stream already read
Calling fetchJSON twice on the same pipe or reading response body manually after fetchJSON.
fixDo not call fetchJSON multiple times; if you need raw response, use ff.fetch and then clone the response.
AbortError: signal is aborted without a reason
Using AbortSignal.timeout(0) or passing an already aborted signal.
fixEnsure timeout is positive and signal is not already aborted. Use AbortSignal.timeout(5000) for a 5-second timeout.
Audit
Dependencies
No dependency data recorded yet.