{"id":47398,"library":"di-fetch","title":"di-fetch","description":"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.","status":"active","version":"0.1.4","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install di-fetch","lang":"bash","label":"npm"},{"cmd":"yarn add di-fetch","lang":"bash","label":"yarn"},{"cmd":"pnpm add di-fetch","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"FetchEngine is a named export, not default. Requires ESM or TypeScript with esModuleInterop.","wrong":"import FetchEngine from 'di-fetch'","symbol":"FetchEngine","correct":"import { FetchEngine } from 'di-fetch'"},{"note":"This is a re-exported fetch function, not the global fetch. Named export only.","wrong":"import fetch from 'di-fetch'","symbol":"fetch","correct":"import { fetch } from 'di-fetch'"},{"note":"Name is exact; renaming is fine but not necessary. Typed as Plugin interface.","wrong":"import { serializeDataPlugin as plugin } from 'di-fetch'","symbol":"serializeDataPlugin","correct":"import { serializeDataPlugin } from 'di-fetch'"},{"note":"Factory function that returns a plugin instance. Used with fetchEngine.use().","wrong":"import { mockPlugin as mock } from 'di-fetch'","symbol":"mockPlugin","correct":"import { mockPlugin } from 'di-fetch'"}],"quickstart":{"code":"import { FetchEngine, serializeDataPlugin } from 'di-fetch';\n\nconst engine = new FetchEngine({\n  baseUrl: 'https://api.example.com',\n  headers: { 'Content-Type': 'application/json' },\n});\n\nengine.use(serializeDataPlugin());\n\nasync function getData() {\n  const response = await engine.get('/data');\n  console.log(response);\n}","lang":"typescript","description":"Creates a FetchEngine with base URL, adds serialization plugin, and performs a GET request."},"warnings":[{"fix":"Always call engine.use(serializeDataPlugin()) when sending JSON data.","message":"FetchEngine instance requires calling use() for plugins; otherwise, requests may fail without serialization.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure each mock object has endpoint (string) and method (string).","message":"mockPlugin expects an array of objects with endpoint, method, response; omitting required fields may cause runtime errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Verify custom client has a request method returning a promise with similar signature.","message":"Custom client must conform to a specific interface (like Taro.request), otherwise unexpected behavior.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.1.4':29 'api':43 'architectur':52 'base':51 'browser':14 'built':17 'built-in':16 'client':10,63 'current':25 'custom':61 'depend':7,68 'dependency-inject':6 'di':2 'di-fetch':1 'didfetch':57 'differenti':48 'engin':46 'extens':45 'extern':67 'fetch':3,41 'fetch-lik':40 'follow':38 'hook':55 'http':9,62 'inject':8 'interceptor':24,54 'javascript':69 'key':47 'lightweight':5 'like':42,64 'mock':22 'node.js':12 'npm':32 'plugin':19,50 'plugin-bas':49 'releas':30 'serial':21 'ship':34 'stabl':26 'support':59 'taro':65 'type':36 'typescript':35,70 'version':27 'via':53 'willfetch':56","created_at":"2026-06-07T16:51:19.279177+00:00","updated_at":"2026-06-07T16:51:19.279177+00:00","problems":[{"fix":"Run npm install di-fetch or yarn add di-fetch.","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'di-fetch'"},{"fix":"Create an instance: const engine = new FetchEngine({...}); then engine.use().","cause":"Using class instead of instance. FetchEngine is a class, not a singleton.","error":"Property 'use' does not exist on type 'typeof FetchEngine'"},{"fix":"Ensure engine is an instance of FetchEngine: const engine = new FetchEngine(options);","cause":"Instance not created properly or method name wrong.","error":"TypeError: engine.get is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"di-fetch","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}