Registry / devops / fetch-parse

fetch-parse

JSON →
library1.1.0jsnpmunverified

Fetch-parse is a mixin for the Fetch API that automatically buffers response bodies and optionally parses them based on the Content-Type header. Version 1.1.0 (latest) is stable with no active development. It supports custom parsers and shorthands for JSON and XML. Key differentiator: eliminates manual res.text()/res.json() calls and provides content-type-driven parsing out of the box.

npm install fetch-parse
INSTALL
IMPORT
SIG · FETCH-PARSE
F
fetch-parse
devopsjavascriptv1.1.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.

fetchParse
import fetchParse from 'fetch-parse'
const fetchParse = require('fetch-parse')
Package is ESM-only, so require() will fail.
fetchParse
const fetchParse = require('fetch-parse')
For CommonJS, use require. Default export is the main function.
FetchParse
import FetchParse from 'fetch-parse'
const { FetchParse } = require('fetch-parse')
FetchParse is not a named export; it's the default.

Basic usage: wraps native fetch to automatically buffer and parse response bodies based on Content-Type.

import fetchParse from 'fetch-parse'; // Create a new fetch function with buffering and default parsing const apiFetch = fetchParse(fetch); // Or with custom parsing for JSON explicitly (redundant but explicit) const apiFetchJson = fetchParse(fetch, { json: true }); // Now use it like regular fetch, but response.body is already parsed apiFetch('https://api.example.com/users') .then(res => { console.log(res.body); // Already parsed JSON object }) .catch(err => console.error(err));
Debug
Known issues
gotchaIf you do not provide a parser configuration, only JSON responses (application/json, */*+json) are parsed by default. Other Content-Types will be buffered as ArrayBuffer.
fix
Specify explicit media type patterns for full control, e.g., fetchParse(fetch, { 'text/*': true, 'application/xml': true, '*/*': true }).
affects: >=1.0.0
gotchaCustom parsers must be provided as functions, not just true. If you pass true, the default parser for that type is used.
fix
Pass a function instead of true for custom parsing, e.g., fetchParse(fetch, { 'text/markdown': (res) => res.text() }).
affects: >=1.0.0
breakingThe package expects the native fetch function (or a polyfill) as the first argument. If fetch is not globally available, you must provide it explicitly.
fix
Pass fetch explicitly: fetchParse(require('node-fetch'), ...) for Node.js or ensure browser fetch is polyfilled.
affects: >=1.0.0
Errors
Common errors & fixes
Error: fetch is not defined
The global fetch function is not available (e.g., in older Node.js versions).
fix
Install node-fetch and pass it to fetchParse: const fetch = require('node-fetch'); const apiFetch = fetchParse(fetch);
TypeError: fetchParse is not a function
Using require() on an ESM-only package.
fix
Use import or set type: module in package.json, or use a dynamic import: const fetchParse = (await import('fetch-parse')).default;
Unhandled promise rejection: TypeError: res.body is undefined
You are accessing response.body but the response has not been fully buffered/parsed yet; or you are using the original fetch instead of the wrapped one.
fix
Ensure you call the wrapped function apiFetch instead of fetch directly.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
medium-typerequiredUsed for media type pattern matching in content-type parsing
fetchoptionalThe native Fetch API is expected as a parameter; not an npm dependency but required at runtime
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-parse — npm install fetch-parse · libregistry