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-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic GET with timeout and JSON response, and POST with JSON body, retry, and status validation.
Catch with (error) => { if (error instanceof Response) { /* handle invalid status */ } }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.
Ensure your environment supports AbortController or use a polyfill like 'abortcontroller-polyfill'.
Use import fetch from 'like-fetch' instead of import likeFetch from 'like-fetch'.
Create your own AbortController and pass signal option.
Use `import fetch from 'like-fetch'` (default import) instead of `import { fetch } from 'like-fetch'`.Ensure body is an object for 'url' type or a FormData instance for 'form' type.
Increase timeout value or check network connectivity. If not expected, set timeout: 0 or omit timeout option.
Adjust validateStatus to accept the status, or handle failed responses differently (e.g., catch and check if error is a Response object).