Registry / devops / like-fetch

like-fetch

JSON →
library2.4.0jsnpmunverified

An enhanced fetch wrapper for Node.js, browsers, and React Native that adds timeout, automatic retries (powered by like-retry), status validation, simplified request/response handling (JSON, URL-encoded, text, form-data), and controller support for manual abort. Current stable version is 2.4.0, with a moderate release cadence. Key differentiators: zero-config default same as native fetch, all features opt-in, lightweight without external dependencies except like-retry. Suitable for projects needing reliable HTTP requests with common patterns built-in.

npm install like-fetch
INSTALL
IMPORT
SIG · LIKE-FETCH
L
like-fetch
devopsjavascriptv2.4.0
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 'like-fetch'
const { fetch } = require('like-fetch')
The package exports a single default function. CommonJS require returns the function directly; named destructuring will fail.
default (fetch) with CommonJS
const fetch = require('like-fetch')
const fetch = require('like-fetch').default
The package is CJS-compatible; require returns the function itself.
TypeScript types
import type { LikeFetchOptions } from 'like-fetch'
import { LikeFetchOptions } from 'like-fetch'
Types are exported as named exports; use import type for type-only imports. Available since v2.0.0.

Shows basic GET with timeout and JSON response, and POST with JSON body, retry, and status validation.

import fetch from 'like-fetch'; // Basic GET request with timeout and JSON response const data = await fetch('https://api.example.com/data', { timeout: 5000, responseType: 'json' }); console.log(data); // POST with retry and status validation const postResult = await fetch('https://api.example.com/create', { method: 'POST', requestType: 'json', body: { name: 'test' }, retry: { max: 3 }, validateStatus: 'ok' }); console.log(postResult);
Debug
Known issues
gotchaWhen validateStatus fails, the entire Response object is thrown, not a regular Error.
fix
Catch with (error) => { if (error instanceof Response) { /* handle invalid status */ } }
affects: >=0.0.0
gotchaThe function returns a Promise<Response> even with responseType set. The responseType only affects how the body is consumed when you call response methods, but the initial promise resolves to the raw Response.
fix
To get the parsed body, use the convenience property: await fetch(...) directly returns the parsed body when responseType is set (since v2.0.0?). Actually the documentation shows const body = await fetch(...) with responseType, which returns the body directly. But the type signature may still indicate Response. Check version behavior.
affects: >=0.0.0
gotchaIn React Native, AbortController may require a polyfill for older versions.
fix
Ensure your environment supports AbortController or use a polyfill like 'abortcontroller-polyfill'.
affects: >=0.0.0
breakingIn v1.x, the default export was named 'likeFetch'. In v2.0.0, it was renamed to 'fetch' as default export.
fix
Use import fetch from 'like-fetch' instead of import likeFetch from 'like-fetch'.
affects: >=2.0.0
deprecatedThe 'controller' property on the promise (e.g., promise.controller) is deprecated in favor of using AbortController directly.
fix
Create your own AbortController and pass signal option.
affects: >=2.0.0
Errors
Common errors & fixes
fetch is not a function
Using named import instead of default import in ESM.
fix
Use `import fetch from 'like-fetch'` (default import) instead of `import { fetch } from 'like-fetch'`.
TypeError: body is not iterable
Using requestType: 'url' with a non-object body, or using requestType: 'form' without FormData.
fix
Ensure body is an object for 'url' type or a FormData instance for 'form' type.
AbortError: The operation was aborted
Request timed out or was manually aborted via controller.abort().
fix
Increase timeout value or check network connectivity. If not expected, set timeout: 0 or omit timeout option.
Error: validateStatus failed (status: 404)
The response status did not satisfy the validateStatus option.
fix
Adjust validateStatus to accept the status, or handle failed responses differently (e.g., catch and check if error is a Response object).
Upgrade
Version history
2.4.0latest on npm
Audit
Dependencies
like-retryoptionalUsed for retry logic when the 'retry' option is provided
Agent activity
4 hits · last 30 days
node
4
Resources