Registry / devops / zl-fetch

zl-fetch

JSON →
library6.3.1jsnpmunverified

zlFetch is an ESM-only wrapper around the native Fetch API providing convenience features like automatic JSON/text/blob parsing, promise-like error handling (400/500 errors go to catch), built-in request abort, automatic Content-Type and Authorization headers, query string helpers, shorthand methods (GET, POST, PUT, PATCH, DELETE), streaming support (SSE, chunked), and instance creation for reusable config. Current stable version 6.3.1 (2023). Released as needed. Differentiators: error handling without try/catch, built-in debug logging, and full response object access without manual .json()/.text(). ESM-only since v4; no CommonJS support.

npm install zl-fetch
INSTALL
IMPORT
SIG · ZL-FETCH
Z
zl-fetch
devopsjavascriptv6.3.1
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
import zlFetch from 'zl-fetch'
const zlFetch = require('zl-fetch')
zlFetch is ESM-only since v4.0.0. CommonJS require() will fail.
zlFetch
import zlFetch from 'zl-fetch'
import { zlFetch } from 'zl-fetch'
Default export only. Named import will be undefined.
z.post
import zlFetch from 'zl-fetch'; const response = await zlFetch.post(url, { body })
Shorthand methods: get, post, put, patch, delete. Called on the default export.

Demonstrates POST request with automatic JSON body serialization, auth header, and error handling.

import zlFetch from 'zl-fetch'; (async () => { try { const response = await zlFetch.post('https://httpbin.org/post', { body: { name: 'zlFetch' }, auth: 'Bearer token' }); console.log(response.data); // parsed body } catch (error) { console.error('Error:', error.status, error.data); } })();
Debug
Known issues
breakingzlFetch v4.0.0 is ESM-only; CommonJS require() will throw an error.
fix
Use import syntax or switch to v3.x (CJS).
affects: >=4.0.0
breakingResponse structure changed in v5: response.data now returns parsed body; old response.body is raw.
fix
Access parsed body via response.data; use response.body for unparsed content.
affects: >=5.0.0
deprecatedzlFetch() default export without arguments is deprecated; use zlFetch.create() for reusable instances.
fix
Use zlFetch.create(baseUrl, options) to create an instance.
affects: >=6.0.0
gotchaAll responses with status >= 400 reject the promise. This includes 400, 401, 404, 500 etc.
fix
Always use try/catch or catch block. For non-error 4xx, consider custom response handler.
affects: >=1.0.0
gotchaAutomatic Content-Type setting: if body is an object, sets application/json; if FormData, removes Content-Type (browser sets).
fix
Override with headers object if custom Content-Type needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: zlFetch is not a function
Using CommonJS require() to import ESM-only module.
fix
Switch to import statement: import zlFetch from 'zl-fetch'
Error: Cannot find module 'zl-fetch'
Package not installed or import path incorrect.
fix
Run 'npm install zl-fetch' and ensure import is 'zl-fetch' not 'zl-fetch/src'.
Uncaught (in promise) TypeError: Failed to parse body
Supplied body is not a valid object, string, or FormData.
fix
Ensure body is JSON-serializable object, plain string, or FormData/Blob.
Response {type: 'cors', status: 0, ...}
Network error or CORS preflight failure; Fetch does not reject on 4xx/5xx.
fix
Check server CORS headers; zlFetch's error handling only applies after successful fetch.
Upgrade
Version history
6.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
Resources
zl-fetch — npm install zl-fetch · libregistry