{"id":47565,"library":"fetch-addons","title":"fetch-addons","description":"A TypeScript-first collection of utility addons for the Fetch API, including helpers to serialize a Request to a cURL command (toCurl), create Request or Headers objects from init parameters (getRequest, getHeaders), and remove empty headers (deleteEmptyHeaders). Version 1.3.0 is stable, requires Node >= 16, and ships TypeScript declarations. Unlike manual fetch wrappers, fetch-addons focuses on debugging and transforming fetch inputs/outputs without patching global fetch.","status":"active","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/smeijer/fetch-addons","tags":["javascript","fetch","fetch-api","fetch-addons","fetch-helpers","fetch-utils","curl","fetch-to-curl","typescript"],"install":[{"cmd":"npm install fetch-addons","lang":"bash","label":"npm"},{"cmd":"yarn add fetch-addons","lang":"bash","label":"yarn"},{"cmd":"pnpm add fetch-addons","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Dev dependency for type checking; package ships types","package":"typescript","optional":true}],"imports":[{"note":"Named export, not default. Works with ESM and CJS via bundler.","wrong":"import toCurl from 'fetch-addons'","symbol":"toCurl","correct":"import { toCurl } from 'fetch-addons'"},{"note":"CommonJS require is possible in Node but ESM is preferred. TypeScript types included.","wrong":"const { getRequest } = require('fetch-addons')","symbol":"getRequest","correct":"import { getRequest } from 'fetch-addons'"},{"note":"All exports are from the package root; no subpath exports.","wrong":"import { getHeaders } from 'fetch-addons/getHeaders'","symbol":"getHeaders","correct":"import { getHeaders } from 'fetch-addons'"},{"note":"Works on Headers objects, not plain objects.","wrong":null,"symbol":"deleteEmptyHeaders","correct":"import { deleteEmptyHeaders } from 'fetch-addons'"},{"note":"Namespace import for all exports. Recommended for non-tree-shaking environments.","wrong":null,"symbol":"*","correct":"import * as addons from 'fetch-addons'"}],"quickstart":{"code":"import { toCurl, getRequest, getHeaders, deleteEmptyHeaders } from 'fetch-addons';\n\n// Convert fetch arguments to a Request object\nconst url = 'https://api.example.com/data';\nconst init = {\n  method: 'POST',\n  headers: {\n    'content-type': 'application/json',\n    'x-api-key': process.env.API_KEY ?? ''\n  },\n  body: JSON.stringify({ foo: 'bar' })\n};\n\nconst request = getRequest(url, init);\nconsole.log(request.method); // 'POST'\n\n// Remove headers with empty values\nconst headers = getHeaders(init.headers);\ndeleteEmptyHeaders(headers);\nconsole.log(headers.get('x-api-key')); // '' (if env not set)\n\n// Serialize to cURL for debugging\nconst curl = toCurl(request);\nconsole.log(curl);\n// curl --url 'https://api.example.com/data' --request 'POST' --header 'content-type: application/json' --data '{\"foo\":\"bar\"}'","lang":"typescript","description":"Demonstrates the four main exports: creating a Request from fetch arguments, manipulating headers, and converting to cURL command."},"warnings":[{"fix":"Manually strip or mask sensitive headers before calling toCurl, or use a wrapper.","message":"toCurl does not redact sensitive headers like Authorization; the cURL output may leak credentials in logs.","severity":"gotcha","affected_versions":">=1.0.0 <=1.3.0"},{"fix":"Pass the Headers object directly and be aware of mutation.","message":"deleteEmptyHeaders only mutates the passed Headers object; it does not return a new Headers instance nor affect the original Request/Response.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If passing a single Request, omit the second argument or pass undefined.","message":"getRequest expects (input, init) signature matching fetch; passing a single Request object is also supported but may cause confusion.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use Node 16+ or provide a global fetch polyfill (e.g., undici, node-fetch).","message":"Package has no runtime dependencies, but requires Node 16+ due to global fetch availability or a fetch polyfill.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.3.0':43 '16':48 'addon':3,11,59,78 'api':15,75 'collect':8 'command':25 'creat':27 'curl':24,85,89 'debug':62 'declar':52 'deleteemptyhead':41 'empti':39 'fetch':2,14,55,58,65,70,72,74,77,80,83,87 'fetch-addon':1,57,76 'fetch-api':73 'fetch-help':79 'fetch-to-curl':86 'fetch-util':82 'first':7 'focus':60 'gethead':36 'getrequest':35 'global':69 'header':30,40 'helper':17,81 'includ':16 'init':33 'inputs/outputs':66 'javascript':71 'manual':54 'node':47 'object':31 'paramet':34 'patch':68 'remov':38 'request':21,28 'requir':46 'serial':19 'ship':50 'stabl':45 'tocurl':26 'transform':64 'typescript':6,51,90 'typescript-first':5 'unlik':53 'util':10,84 'version':42 'without':67 'wrapper':56","created_at":"2026-06-07T16:52:10.024182+00:00","updated_at":"2026-06-07T16:52:10.024182+00:00","problems":[{"fix":"Run 'npm install fetch-addons' and ensure import uses the package name exactly: 'import { toCurl } from 'fetch-addons'.","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'fetch-addons' or its corresponding type declarations."},{"fix":"Change 'import deleteEmptyHeaders from 'fetch-addons'' to 'import { deleteEmptyHeaders } from 'fetch-addons'.","cause":"Using default import instead of named import.","error":"TypeError: deleteEmptyHeaders is not a function"},{"fix":"Convert FormData to a string or use a different tool for multipart requests.","cause":"toCurl only serializes string bodies; FormData is not supported.","error":"toCurl does not convert multipart/form-data bodies correctly."},{"fix":"Provide a default empty Headers: 'getHeaders(init.headers ?? {})'.","cause":"getHeaders does not handle undefined or null headersInit gracefully.","error":"getHeaders(init.headers) is undefined when init.headers is not provided."}],"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/smeijer/fetch-addons#readme","github":"https://github.com/smeijer/fetch-addons","docs":null,"changelog":null,"pypi":null,"npm":"fetch-addons","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","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}}