Registry / networking / wya-fetch

wya-fetch

JSON →
library0.5.4jsnpmunverified

A lightweight HTTP request library for JavaScript, wrapping the Fetch API with middleware-like hooks (onLoading, onLoaded, onBefore, onAfter, onOther, onProgress) and support for cancelable requests via HotPromise. Version 0.5.4 is stable, with irregular releases. Key differentiators: integrates with UI loading states out of the box, provides a clean ajaxFn factory pattern for reusable defaults, and handles form-data/json request types including a special mixed mode for POST. Alternatives like axios are more feature-rich but wya-fetch focuses on simplicity and hook-based customization.

npm install wya-fetch
INSTALL
IMPORT
SIG · WYA-FETCH
W
wya-fetch
networkingjavascriptv0.5.4
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.

ajaxFn
import { ajaxFn } from 'wya-fetch'
import wyaFetch from 'wya-fetch'
Use named import for the factory function; package does not export a default

Shows how to create an ajaxFn instance with default hooks, perform GET and POST requests with cancellation.

import { ajaxFn } from 'wya-fetch'; // Create an instance with default options const ajax = ajaxFn({ onLoading: (opts, xhr) => console.log('Loading...'), onLoaded: (opts, xhr) => console.log('Loaded'), onBefore: (opts, xhr) => Promise.resolve(opts), onAfter: (response, opts, xhr) => Promise.resolve(response), onOther: (response, resolve, reject) => { if (response.status === 401) { console.error('Unauthorized'); reject(response); } else { resolve(response); } } }); // Make a GET request ajax({ url: '/api/items', type: 'GET', param: { page: 1 } }) .then(res => console.log('Success:', res)) .catch(err => console.error('Error:', err)); // Make a POST request with JSON body ajax({ url: '/api/login', type: 'POST', param: { user: 'admin', pass: '123' }, requestType: 'json' }) .then(res => console.log('Login:', res)) .catch(err => console.error('Login failed:', err)); // Cancel a request let cancel; const request = ajax({ url: '/api/slow', getCancel: cb => cancel = cb }); cancel(); // Aborts the request
Debug
Known issues
breakingIn version 0.3.0, the ajaxFn factory was rewritten to use defaultOptions as a function argument instead of previous behavior. Existing code passing default options differently will break.
fix
Update calls to ajaxFn to pass defaultOptions as an object: ajaxFn({ onLoading: ... }) instead of using separate setup.
affects: <0.3.0
breakingThe package previously exported a default class for ajax; from 0.3.0 onward only the named export ajaxFn is provided.
fix
Change import from 'import MyFetch from "wya-fetch"' to 'import { ajaxFn } from "wya-fetch"' and use ajaxFn to create instance.
affects: <0.3.0
gotcharequestType: 'json' does NOT set Content-Type to application/json automatically; the library relies on the browser's fetch API which sets it based on body type. For POST JSON requests, ensure body is serialized correctly.
fix
Use requestType: 'json' and the library will stringify the param object for you. The fetch will set Content-Type to application/json.
affects: all
gotchaThe cancel functionality uses a custom HotPromise; calling cancel() after the request has already completed may throw an error.
fix
Check if the promise is pending before cancelling, or wrap cancel in try/catch.
affects: all
deprecatedThe onProgress callback is deprecated in newer versions; use onUploadProgress instead? Unclear from README.
fix
Refer to CHANGELOG or source code to check if onProgress is still supported.
affects: >=0.5.0
Errors
Common errors & fixes
import { ajaxFn } from 'wya-fetch' does not work: TypeError: wya_fetch_1.ajaxFn is not a function
The package was imported incorrectly, possibly due to mixing CommonJS/ESM or using an older version that exports differently.
fix
Ensure you are using a JavaScript bundler that supports ES modules (webpack, rollup, vite) and that the package version is at least 0.3.0. Try: import { ajaxFn } from 'wya-fetch';
Unhandled Promise Rejection: TypeError: Failed to fetch
The URL is invalid or CORS is misconfigured. Or the network is offline.
fix
Check the URL format and ensure the server supports CORS. For local development, use a proxy or server with correct headers.
ajax is not a function
The returned value from ajaxFn is being used directly without being called as a function (e.g., calling net.ajax() instead of net.ajax).
fix
Ensure that after creating ajax = ajaxFn(), you call ajax(options) to make a request.
Upgrade
Version history
0.5.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
26
OpenAI (training)
1
Resources
wya-fetch — npm install wya-fetch · libregistry