Registry / devops / yz-fetch

yz-fetch

JSON →
library1.1.12jsnpmunverified

A lightweight HTTP client library for Node.js and the browser, version 1.1.12. Provides a fetch-like API with additional features such as request/response interceptors, automatic JSON parsing, timeout support, and TypeScript types included. It is designed to be a simple alternative to axios or ky with zero dependencies. However, as of version 1.1.12, it has very limited documentation and community adoption.

npm install yz-fetch
INSTALL
IMPORT
SIG · YZ-FETCH
Y
yz-fetch
devopsjavascriptv1.1.12
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.

yzfetch
import yzfetch from 'yz-fetch'
const yzfetch = require('yz-fetch')
ESM only; CJS require will fail if module is not transpiled.
yzfetch
import { default as yzfetch } from 'yz-fetch'
Named import of default export is also valid.
YzFetchError
import { YzFetchError } from 'yz-fetch'
import YzFetchError from 'yz-fetch'
YzFetchError is a named export, not a default export.
RequestInterceptor
import type { RequestInterceptor } from 'yz-fetch'
import { RequestInterceptor } from 'yz-fetch'
RequestInterceptor is a type, so import type is preferred. In TypeScript, you can use `import type`.

Demonstrates a basic GET request with authentication and a timeout option using yz-fetch.

import yzfetch from 'yz-fetch'; try { const data = await yzfetch('https://api.example.com/data', { method: 'GET', headers: { 'Authorization': `Bearer ${process.env.API_KEY ?? ''}` } }); console.log(data); } catch (error) { console.error(error); } // With timeout const response = await yzfetch('https://api.example.com/data', { timeout: 5000 }); console.log(response);
Debug
Known issues
gotchayz-fetch returns parsed JSON automatically if Content-Type is application/json. To get raw response, use the `raw` option or access `response.text()`.
fix
Use `{ raw: true }` to get the raw Response object.
affects: >=1.0.0
gotchaNo default export type for yzfetch function; TypeScript users must rely on the function type from the module.
fix
Use `import yzfetch from 'yz-fetch'` and rely on TypeScript inference.
affects: >=1.0.0
deprecatedThe `onRequest` interceptor alias has been deprecated in favor of `requestInterceptor`.
fix
Replace `onRequest` with `requestInterceptor`.
affects: >=1.1.0
gotchaError handling: non-2xx status codes throw an error; catch block receives an instance of YzFetchError with `status` and `data` properties.
fix
Catch errors and check `error.status` for HTTP status.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'yz-fetch'
Module not installed or wrong import syntax.
fix
Run `npm install yz-fetch` and use correct ESM import: `import yzfetch from 'yz-fetch'`.
TypeError: yzfetch is not a function
Default import not used correctly; likely using named import instead.
fix
Use `import yzfetch from 'yz-fetch'` (default import).
Property 'onRequest' does not exist on type...
Using deprecated interceptor name.
fix
Replace `onRequest` with `requestInterceptor` in configuration.
Upgrade
Version history
1.1.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
Resources
yz-fetch — npm install yz-fetch · libregistry