return-fetch v0.4.8 is a lightweight TypeScript library (under 1KB gzipped) that wraps the native fetch API to provide request/response interceptors, base URL prefixing, and default headers. It is designed as a higher-order function, returning an enhanced fetch function with the same interface, making it ideal for Next.js App Router (which uses a patched fetch) and isomorphic usage. Unlike Axios or ky, it does not introduce new APIs or create custom adapters; instead, it composes naturally with existing fetch patterns. The library is ESM-first with CommonJS fallback, ships TypeScript definitions, and is actively maintained with regular releases.
npm install return-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates an enhanced fetch with base URL, default headers, and request/response interceptors for logging and error handling.
Ensure the environment supports fetch, or add a polyfill like 'whatwg-fetch'.
Use const returnFetch = require('return-fetch').default;To override a default header, explicitly set it in the request object passed to the returned fetch function.
Update interceptor to return a tuple [url, init] instead of the full args array.
Switch to `import returnFetch from 'return-fetch'`.
Install the package: npm install return-fetch. Ensure tsconfig.json includes 'moduleResolution': 'node' or 'bundler'.
Use `import returnFetch from 'return-fetch'` in ESM, or `const returnFetch = require('return-fetch').default` in CJS.Upgrade to v0.4.0+ and use the option as specified. In older versions, use 'baseUrl' (lowercase 'u') if available.
No dependency data recorded yet.