Registry / testing / fetch-class

fetch-class

JSON →
library1.0.4jsnpmunverified

An ES6 class wrapper for the Fetch API, providing a simplified interface with convenience methods (get, post, put, patch, del) and event hooks (request:pre, request:post). Version 1.0.4 is stable but appears unmaintained since 2017. It extends native fetch with base URL prefixing, default options, callbacks, and query parameter handling. Unlike raw fetch or axios, it offers a class-based design with event triggers for extensibility. Suitable for legacy browser projects where a simple fetch wrapper is needed, but lacks modern TypeScript types and ESM-only support.

npm install fetch-class
INSTALL
IMPORT
SIG · FETCH-CLASS
F
fetch-class
testingjavascriptv1.0.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.

default
import Fetch from 'fetch-class'
const { Fetch } = require('fetch-class');
Package exports a single default class. CommonJS destructuring will fail.
Fetch (constructor)
import Fetch from 'fetch-class'; new Fetch('https://api.example.com')
new fetch('https://api.example.com')
The default export is a class, not a function. Capitalize constructor.
Instance methods
import Fetch from 'fetch-class'; const api = new Fetch(); api.get('/posts/', response => console.log(response))
import { get } from 'fetch-class';
Methods are not exported; they must be accessed on an instance.

Demonstrates creating an instance with base URL and performing GET, POST, and DELETE requests with callbacks.

import Fetch from 'fetch-class'; import 'whatwg-fetch'; const api = new Fetch('https://jsonplaceholder.typicode.com'); api.get('/posts/1', (response) => { console.log('Response:', response); }); api.post('/posts', { title: 'foo', body: 'bar', userId: 1 }, (response) => { console.log('Created:', response); }); api.del('/posts/1', (response) => { console.log('Deleted:', response); });
Debug
Known issues
deprecatedPackage is deprecated. No updates since 2017. Not compatible with modern fetch standards or TypeScript.
fix
Migrate to native fetch or a maintained library like ky or axios.
affects: >=1.0.0
gotchaCallbacks are used instead of Promises. The response is not a standard Response object but processed JSON/text.
fix
Use the callback pattern as documented. If you need Promises, wrap the call manually.
affects: *
gotchaThe 'del' method is used for DELETE requests. Using 'delete' as a variable name causes syntax errors in strict mode.
fix
Use api.del('/path', callback) instead of api.delete().
affects: *
gotchaDefault headers include 'Content-Type': 'application/json'. For requests without a body (GET, DELETE), this may cause unnecessary preflight CORS requests.
fix
Override defaultOptions.headers to exclude Content-Type for GET/DELETE if CORS is an issue.
affects: *
breakingVersion 0.x used a different API; baseUrl was mandatory and defaultOptions had different structure.
fix
Upgrade to 1.x; see changelog for migration.
affects: <1.0.0
Errors
Common errors & fixes
TypeError: fetch is not defined
Environment lacks native fetch (e.g., Node.js <18 or older browser).
fix
Install and import a polyfill: npm install whatwg-fetch, then add 'import "whatwg-fetch";' before using fetch-class.
TypeError: (intermediate value) is not a function
Using require('fetch-class') without default import, e.g., const Fetch = require('fetch-class'); Fetch is an object with Fetch class.
fix
Use const Fetch = require('fetch-class').default; or switch to import Fetch from 'fetch-class'.
DELETE requests fail silently
Using 'delete' as a variable name (reserved keyword) in older environments.
fix
Use the 'del' method instead: instance.del(url, callback).
CORS errors in browser
Default Content-Type header triggers preflight for all requests.
fix
Set defaultOptions.headers = { 'Accept': 'application/json' } on instances for GET/DELETE.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
whatwg-fetchoptionalRequired for environments that lack native fetch (e.g., older browsers, Node <18)
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-class — npm install fetch-class · libregistry