{"id":49831,"library":"zhi-fetch-middleware","title":"zhi-fetch-middleware","description":"A lightweight middleware layer for fetch requests that allows adding interceptors (before, after) and error handling. Version 0.13.5 is the latest stable release, with no external dependencies. It provides a simple API to compose middleware functions for modifying requests and responses, similar to Express middleware but for the Fetch API. Ships TypeScript definitions. Suitable for small to medium projects needing request/response transforms or logging.","status":"active","version":"0.13.5","language":"javascript","source_language":"en","source_url":"https://github.com/terwer/zhi","tags":["javascript","zhi","lib","typescript"],"install":[{"cmd":"npm install zhi-fetch-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add zhi-fetch-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add zhi-fetch-middleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export only, no default export.","wrong":"import createMiddleware from 'zhi-fetch-middleware'","symbol":"createMiddleware","correct":"import { createMiddleware } from 'zhi-fetch-middleware'"},{"note":"Type import for TypeScript: import type { FetchMiddleware } from 'zhi-fetch-middleware'","wrong":"import { FetchMiddleware } from 'zhi-fetch-middleware'","symbol":"FetchMiddleware","correct":"import { FetchMiddleware } from 'zhi-fetch-middleware'"},{"note":"ESM-only package; CommonJS require is not supported.","wrong":"const { applyMiddleware } = require('zhi-fetch-middleware')","symbol":"applyMiddleware","correct":"import { applyMiddleware } from 'zhi-fetch-middleware'"}],"quickstart":{"code":"import { createMiddleware, applyMiddleware } from 'zhi-fetch-middleware';\n\nconst loggerMiddleware = createMiddleware({\n  before: async (request) => {\n    console.log('Fetching:', request.url);\n    return request;\n  },\n  after: async (response) => {\n    console.log('Response status:', response.status);\n    return response;\n  }\n});\n\nconst enhancedFetch = applyMiddleware(fetch, [loggerMiddleware]);\n\n(async () => {\n  const response = await enhancedFetch('https://api.example.com/data', {\n    method: 'GET',\n    headers: { 'Content-Type': 'application/json' }\n  });\n  const data = await response.json();\n  console.log(data);\n})();","lang":"typescript","description":"Creates a simple logger middleware that logs requests and responses, then applies it to fetch to produce an enhanced fetch function."},"warnings":[{"fix":"Migrate to using createMiddleware() and applyMiddleware() as described in the docs.","message":"Version 0.12.0 changed the API from an object-based configuration to a function-based one. Old usage with middleware config object no longer works.","severity":"breaking","affected_versions":">=0.12.0"},{"fix":"Replace with applyMiddleware() which is the new standard.","message":"The method 'useMiddleware' is deprecated and will be removed in v1.0.","severity":"deprecated","affected_versions":">=0.13.0"},{"fix":"Ensure all middleware functions are async.","message":"Middleware functions must be async or return a Promise, otherwise they may be skipped.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.13.5':22 'ad':14 'allow':13 'api':36,54 'compos':38 'definit':57 'depend':31 'error':19 'express':48 'extern':30 'fetch':3,10,53 'function':40 'handl':20 'interceptor':15 'javascript':69 'latest':25 'layer':8 'lib':71 'lightweight':6 'log':68 'medium':62 'middlewar':4,7,39,49 'modifi':42 'need':64 'project':63 'provid':33 'releas':27 'request':11,43 'request/response':65 'respons':45 'ship':55 'similar':46 'simpl':35 'small':60 'stabl':26 'suitabl':58 'transform':66 'typescript':56,72 'version':21 'zhi':2,70 'zhi-fetch-middlewar':1","created_at":"2026-06-07T17:03:49.356908+00:00","updated_at":"2026-06-07T17:03:49.356908+00:00","problems":[{"fix":"Use `import { createMiddleware } from 'zhi-fetch-middleware'`","cause":"Default import used instead of named import.","error":"TypeError: createMiddleware is not a function"},{"fix":"Import only from 'zhi-fetch-middleware' directly.","cause":"Trying to import from an internal path that is not exposed via package.json exports.","error":"ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './dist/index.js' is not defined","error_detail":"May also appear as 'Cannot find module'"}],"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":"https://github.com/terwer/zhi/tree/main/libs/zhi-fetch-middleware","github":"https://github.com/terwer/zhi","docs":null,"changelog":null,"pypi":null,"npm":"zhi-fetch-middleware","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}}