{"library":"make-fetch-happen","title":"make-fetch-happen","description":"make-fetch-happen is an opinionated, robust Node.js HTTP client that extends the standard `fetch` API with critical features for real-world applications. Currently stable at version 15.0.5, it maintains a fairly active release cadence, with minor/patch updates occurring every few months and major versions roughly annually, aligning with Node.js LTS updates. It distinguishes itself by wrapping `minipass-fetch` and augmenting it with capabilities like automatic HTTP-semantics-aware request retries, comprehensive HTTP caching (`Cache-Control`, `ETag`, `304`s, offline fallback), request pooling, transparent gzip/deflate, and support for proxies (HTTP, HTTPS, SOCKS). Additionally, it provides Subresource Integrity (SRI) verification and integrates Node.js Stream support, making it a highly reliable and performant choice for network operations within the Node.js ecosystem, particularly for tools like `npm` itself.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install make-fetch-happen"],"cli":null},"imports":["import makeFetchHappen from 'make-fetch-happen'; const fetch = makeFetchHappen;","import makeFetchHappen from 'make-fetch-happen'; const fetchWithDefaults = makeFetchHappen.defaults({ /* options */ });","import makeFetchHappen, { Response } from 'make-fetch-happen'; // Or globally available in Node.js >=18"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import makeFetchHappen from 'make-fetch-happen';\n\nconst fetch = makeFetchHappen.defaults({\n  cachePath: './my-app-cache' // path where cache will be written (and read)\n});\n\n// First request: fetches from the web and caches the response\nfetch('https://registry.npmjs.org/make-fetch-happen')\n  .then(res => res.json()) // download the body as JSON\n  .then(body => {\n    console.log(`Initial fetch: got ${body.name} from web.`);\n    // Second request: forces a conditional request to validate cache\n    return fetch('https://registry.npmjs.org/make-fetch-happen', {\n      cache: 'no-cache' // instructs to revalidate with the origin\n    });\n  })\n  .then(res => {\n    console.log(`Conditional fetch status: ${res.status}`); // Expected 304 if cache valid\n    return res.json().then(body => {\n      console.log(`Conditional fetch: got ${body.name} from cache (status ${res.status}).`);\n    });\n  })\n  .catch(error => console.error('An error occurred:', error));\n","lang":"typescript","description":"This quickstart demonstrates how to configure `make-fetch-happen` with a persistent cache path and perform both initial and conditional HTTP requests, showcasing its caching capabilities.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}