Registry / devops / di-fetch

di-fetch

JSON →
library0.1.4jsnpmunverified

A lightweight, dependency-injected HTTP client for Node.js and browser with built-in plugins for serialization, mocking, and interceptors. Current stable version is 0.1.4, released on npm. It ships TypeScript types and follows a fetch-like API with extensible engine. Key differentiator: plugin-based architecture via interceptor hooks (willFetch, didFetch) and support for custom HTTP clients like Taro. No external dependencies.

npm install di-fetch
INSTALL
IMPORT
SIG · DI-FETCH
D
di-fetch
devopsjavascriptv0.1.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.

FetchEngine
import { FetchEngine } from 'di-fetch'
import FetchEngine from 'di-fetch'
FetchEngine is a named export, not default. Requires ESM or TypeScript with esModuleInterop.
fetch
import { fetch } from 'di-fetch'
import fetch from 'di-fetch'
This is a re-exported fetch function, not the global fetch. Named export only.
serializeDataPlugin
import { serializeDataPlugin } from 'di-fetch'
import { serializeDataPlugin as plugin } from 'di-fetch'
Name is exact; renaming is fine but not necessary. Typed as Plugin interface.
mockPlugin
import { mockPlugin } from 'di-fetch'
import { mockPlugin as mock } from 'di-fetch'
Factory function that returns a plugin instance. Used with fetchEngine.use().

Creates a FetchEngine with base URL, adds serialization plugin, and performs a GET request.

import { FetchEngine, serializeDataPlugin } from 'di-fetch'; const engine = new FetchEngine({ baseUrl: 'https://api.example.com', headers: { 'Content-Type': 'application/json' }, }); engine.use(serializeDataPlugin()); async function getData() { const response = await engine.get('/data'); console.log(response); }
Debug
Known issues
gotchaFetchEngine instance requires calling use() for plugins; otherwise, requests may fail without serialization.
fix
Always call engine.use(serializeDataPlugin()) when sending JSON data.
affects: >=0.1.0
gotchamockPlugin expects an array of objects with endpoint, method, response; omitting required fields may cause runtime errors.
fix
Ensure each mock object has endpoint (string) and method (string).
affects: >=0.1.0
gotchaCustom client must conform to a specific interface (like Taro.request), otherwise unexpected behavior.
fix
Verify custom client has a request method returning a promise with similar signature.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'di-fetch'
Package not installed or not in node_modules.
fix
Run npm install di-fetch or yarn add di-fetch.
Property 'use' does not exist on type 'typeof FetchEngine'
Using class instead of instance. FetchEngine is a class, not a singleton.
fix
Create an instance: const engine = new FetchEngine({...}); then engine.use().
TypeError: engine.get is not a function
Instance not created properly or method name wrong.
fix
Ensure engine is an instance of FetchEngine: const engine = new FetchEngine(options);
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
di-fetch — npm install di-fetch · libregistry