{"id":47594,"library":"fetch-h","title":"fetch-h2","description":"A Fetch API client for Node.js that supports HTTP/1.1 and HTTP/2 with automatic protocol negotiation via ALPN. Current stable version is 3.0.2, published on npm, with semi-regular releases. Key differentiators include transparent HTTP/2 support, cookie management, built-in response compression (br, gzip, deflate), and TypeScript types. It uses the native Node.js http, https, and http2 modules without external dependencies, and manages sessions and socket reuse automatically. It provides a familiar browser-like fetch API extended for Node.js streams and offers context-based cookies and custom decoders.","status":"active","version":"3.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/grantila/fetch-h2","tags":["javascript","fetch","h2","http2","client","request","api","typesafe","typescript"],"install":[{"cmd":"npm install fetch-h","lang":"bash","label":"npm"},{"cmd":"yarn add fetch-h","lang":"bash","label":"yarn"},{"cmd":"pnpm add fetch-h","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"fetch is a named export, not a default export. Common mistake when migrating from node-fetch.","wrong":"import fetch from 'fetch-h2'","symbol":"fetch","correct":"import { fetch } from 'fetch-h2'"},{"note":"ESM-only package since v3; CommonJS require() will fail. Use import syntax.","wrong":"const { Headers } = require('fetch-h2')","symbol":"Headers","correct":"import { Headers } from 'fetch-h2'"},{"note":"AbortController is a named export. Renaming is fine but unnecessary.","wrong":"import { AbortController as AC } from 'fetch-h2'; const controller = new AC();","symbol":"AbortController","correct":"import { AbortController } from 'fetch-h2'"}],"quickstart":{"code":"import { fetch } from 'fetch-h2';\n\nasync function main() {\n  try {\n    const response = await fetch('https://httpbin.org/get', {\n      headers: { 'User-Agent': 'fetch-h2/3.0' }\n    });\n    if (!response.ok) {\n      throw new Error(`HTTP error! status: ${response.status}`);\n    }\n    const data = await response.json();\n    console.log(data);\n  } catch (error) {\n    console.error('Fetch failed:', error);\n  }\n}\n\nmain();","lang":"typescript","description":"Performs a GET request to httpsbin.org using fetch-h2, checks the response status, and parses JSON body."},"warnings":[{"fix":"Upgrade Node.js to 12 or higher.","message":"Requires Node.js >= 12 for version 3.x. Node.js 10 support dropped.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use import syntax (e.g., import { fetch } from 'fetch-h2') or switch to dynamic import().","message":"ESM-only package since version 3.0.0. CommonJS require() will throw an error.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Pass context options directly to fetch() instead of using context().","message":"The 'context' export is deprecated in favor of per-request options.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Example: fetch(url, { redirect: 'follow' })","message":"fetch() does not follow redirects automatically by default; you must set 'redirect: 'follow' option.","severity":"gotcha","affected_versions":"*"},{"fix":"Use 'http2://' for h2c connections.","message":"HTTP/2 connections over plain-text require 'http2://' scheme; 'http://' defaults to HTTP/1.1.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'3.0.2':25 'alpn':20 'api':6,81,101 'automat':16,72 'base':90 'br':47 'browser':78 'browser-lik':77 'built':43 'built-in':42 'client':7,99 'compress':46 'context':89 'context-bas':88 'cooki':40,91 'current':21 'custom':93 'decod':94 'deflat':49 'depend':65 'differenti':35 'extend':82 'extern':64 'familiar':76 'fetch':2,5,80,96 'fetch-h2':1 'gzip':48 'h2':3,97 'http':58 'http/1.1':12 'http/2':14,38 'http2':61,98 'https':59 'includ':36 'javascript':95 'key':34 'like':79 'manag':41,67 'modul':62 'nativ':56 'negoti':18 'node.js':9,57,84 'npm':28 'offer':87 'protocol':17 'provid':74 'publish':26 'regular':32 'releas':33 'request':100 'respons':45 'reus':71 'semi':31 'semi-regular':30 'session':68 'socket':70 'stabl':22 'stream':85 'support':11,39 'transpar':37 'type':52 'typesaf':102 'typescript':51,103 'use':54 'version':23 'via':19 'without':63","created_at":"2026-06-07T16:52:18.932567+00:00","updated_at":"2026-06-07T16:52:18.932567+00:00","problems":[{"fix":"Use dynamic import() or switch to ES modules (e.g., \"type\": \"module\" in package.json).","cause":"Requiring an ESM-only package with CommonJS require() in Node.js 12+.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/fetch-h2/... not supported"},{"fix":"Use import { fetch } from 'fetch-h2' instead of import fetch from 'fetch-h2'.","cause":"Importing the default export instead of named export.","error":"TypeError: fetch is not a function"},{"fix":"Set a timeout via AbortController or use the 'timeout' option if supported (community note: not officially documented).","cause":"The request exceeded the default timeout (usually no timeout set but explicit abort).","error":"TimeoutError: The operation was aborted"}],"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/grantila/fetch-h2#readme","github":"https://github.com/grantila/fetch-h2","docs":null,"changelog":null,"pypi":null,"npm":"fetch-h","openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"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}}