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-classNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating an instance with base URL and performing GET, POST, and DELETE requests with callbacks.
Migrate to native fetch or a maintained library like ky or axios.
Use the callback pattern as documented. If you need Promises, wrap the call manually.
Use api.del('/path', callback) instead of api.delete().Override defaultOptions.headers to exclude Content-Type for GET/DELETE if CORS is an issue.
Upgrade to 1.x; see changelog for migration.
Install and import a polyfill: npm install whatwg-fetch, then add 'import "whatwg-fetch";' before using fetch-class.
Use const Fetch = require('fetch-class').default; or switch to import Fetch from 'fetch-class'.Use the 'del' method instead: instance.del(url, callback).
Set defaultOptions.headers = { 'Accept': 'application/json' } on instances for GET/DELETE.