{"id":48156,"library":"http-with-fetch","title":"http-with-fetch","description":"A tiny abstraction over the Fetch API for building featureful API clients. Current version 3.3.6. Released regularly on npm. Provides a CredentialsManager and visitor pattern for request/response handling, plus a TestHarness for mocking HTTP calls in tests using Node.js built-in test framework. Distinguishes itself by being lightweight (1.3KB bundle) and focused on the fetch API with no external runtime dependencies.","status":"active","version":"3.3.6","language":"javascript","source_language":"en","source_url":"https://github.com/aulisius/http-with-fetch","tags":["javascript","fetch","http"],"install":[{"cmd":"npm install http-with-fetch","lang":"bash","label":"npm"},{"cmd":"yarn add http-with-fetch","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-with-fetch","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only package since v3. CommonJS require() will not work.","wrong":"const createApiClient = require('http-with-fetch')","symbol":"createApiClient","correct":"import { createApiClient } from 'http-with-fetch'"},{"note":"CredentialsManager is exported from main entry, not from harness path.","wrong":"import { CredentialsManager } from 'http-with-fetch/harness'","symbol":"CredentialsManager","correct":"import { CredentialsManager } from 'http-with-fetch'"},{"note":"TestHarness is exported from a separate subpath 'http-with-fetch/harness'.","wrong":"import { TestHarness } from 'http-with-fetch'","symbol":"TestHarness","correct":"import { TestHarness } from 'http-with-fetch/harness'"}],"quickstart":{"code":"import { createApiClient, CredentialsManager } from 'http-with-fetch';\n\nclass DefaultCredentialsManager implements CredentialsManager {\n  async attach(init: RequestInit, url: string) {\n    init.credentials = 'include';\n    return { init, url };\n  }\n  async isValid(_: Request, res: Response) {\n    if (res.status === 401) return false;\n    return true;\n  }\n}\n\nconst visitor = {\n  async ok(response: Response) {\n    return response.json();\n  },\n  async fail(request: Request, response: Response) {\n    let error = await response.json();\n    if (process.env.NODE_ENV !== 'production') {\n      console.error('API Call Failed: ', error, request);\n    }\n    throw new Error(error.message || 'Request failed');\n  },\n};\n\nconst credentials = new DefaultCredentialsManager();\nconst client = createApiClient({ credentials, visitor }, false);\n\n// Usage\nconst list = await client.get('/resource', { limit: 10 });\nconsole.log(list);","lang":"typescript","description":"Shows how to create an API client with custom credentials manager and visitor for response handling, then make a GET request."},"warnings":[{"fix":"Use client.execute({ method: 'GET', url: '/path' }) instead of client.get('/path') when you need to mock requests with TestHarness.","message":"TestHarness only works when using client.execute() method, not other shortcut methods like client.get() or client.post().","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Use import syntax or dynamic import('http-with-fetch'). Ensure your project is configured for ESM (type: 'module' in package.json).","message":"The library is ESM-only starting from version 3. CommonJS require() will fail.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Update TestHarness constructor calls: new TestHarness(client, t, handler) instead of old signature.","message":"The 'TestHarness' previously required the mock to be passed as second argument; now it's the third argument after client and test context.","severity":"deprecated","affected_versions":">=3.2.0"}],"env_vars":null,"search_vec":"'1.3':54 '3.3.6':19 'abstract':7 'api':11,15,62 'build':13 'built':45 'built-in':44 'bundl':56 'call':39 'client':16 'credentialsmanag':26 'current':17 'depend':67 'distinguish':49 'extern':65 'featur':14 'fetch':4,10,61,69 'focus':58 'framework':48 'handl':32 'http':2,38,70 'http-with-fetch':1 'javascript':68 'kb':55 'lightweight':53 'mock':37 'node.js':43 'npm':23 'pattern':29 'plus':33 'provid':24 'regular':21 'releas':20 'request/response':31 'runtim':66 'test':41,47 'testhar':35 'tini':6 'use':42 'version':18 'visitor':28","created_at":"2026-06-07T16:55:12.350035+00:00","updated_at":"2026-06-07T16:55:12.350035+00:00","problems":[{"fix":"import { TestHarness } from 'http-with-fetch/harness'","cause":"Import path for TestHarness is incorrect; using 'http-with-fetch' instead of 'http-with-fetch/harness'.","error":"Cannot find module 'http-with-fetch/harness'"},{"fix":"Pass visitor to createApiClient: createApiClient({ credentials, visitor })","cause":"Client created without visitors; get/post shortcuts require visitor object.","error":"TypeError: client.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":"https://github.com/aulisius/http-with-fetch#readme","github":"https://github.com/aulisius/http-with-fetch","docs":null,"changelog":null,"pypi":null,"npm":"http-with-fetch","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"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}}