An extended fetch function that automatically serializes request bodies as JSON and deserializes response bodies as JSON objects. Built on top of return-fetch, it provides a thin, typed wrapper around the native fetch API. Current stable version is 0.4.8 (released 2024). The package is actively maintained, releases are versioned on npm, and it ships TypeScript definitions. Key differentiators: zero dependencies, small bundle size, custom parser support, and integration with base URL and default headers from return-fetch. Ideal for developers who want a lightweight JSON-aware fetch without the overhead of Axios or ky.
npm install return-fetch-jsonNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating an extended fetch with base URL, making POST and GET requests, and automatically serializing/deserializing JSON objects.
Ensure body is JSON-serializable (pass null or undefined for non-JSON bodies).
Use async/await or .then() when calling the extended fetch function.
Replace `jsonParser` with `deserialize` in the configuration object.
Either provide a `baseUrl` option or use absolute URLs in fetch calls.
Use `fetchExtended<ExpectedBody>(...)` only for the body shape; do not expect the entire response to be typed as T.
Run `npm install return-fetch-json` (or yarn/pnpm equivalent) in your project.
Use `import returnFetchJson from 'return-fetch-json'` (default import).
Only pass plain objects or arrays as body; for FormData, use the native fetch directly.