Registry / testing / fetch-fun

fetch-fun

JSON →
library0.4.2jsnpmunverified

fetch-fun is a lightweight, TypeScript-native HTTP client built on the Fetch API. It offers a functional pipe-based API for composing request configurations such as base URL, headers, methods, JSON body, retry, and timeout. Currently at version 0.4.2, the library is in active development with frequent releases. Unlike heavier alternatives like axios or ky, fetch-fun provides a composable, tree-shakeable approach without wrapping the native fetch, making it ideal for modern JS/TS environments. It ships complete TypeScript definitions and requires no external dependencies.

npm install fetch-fun
INSTALL
IMPORT
SIG · FETCH-FUN
F
fetch-fun
testingjavascriptv0.4.2
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.

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.
fix
Migrate 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.
fix
Use .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.
fix
Use .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.
fix
Replace .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.
fix
Add 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.
fix
Use 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.
fix
Run 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.
fix
Do 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.
fix
Ensure timeout is positive and signal is not already aborted. Use AbortSignal.timeout(5000) for a 5-second timeout.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fetch-fun — npm install fetch-fun · libregistry