{"id":16060,"library":"http-call","title":"http-call","description":"http-call is a lightweight, promise-based HTTP client designed for making RESTful API requests. Maintained by Heroku, it provides a fluent interface for common HTTP methods (GET, POST, PUT, DELETE) and simplifies interaction with JSON APIs by automatically converting responses. The current stable version is 5.5.1, with a release cadence that includes regular bug fixes and minor feature enhancements. Key differentiators include built-in TypeScript support, automatic JSON parsing, and a focus on clean, asynchronous API consumption, making it suitable for modern Node.js applications that require robust HTTP communication without extensive configuration. It is widely used within the Heroku ecosystem for interacting with platform services.","status":"active","version":"5.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/heroku/http-call","tags":["javascript","http","request","rest","typescript"],"install":[{"cmd":"npm install http-call","lang":"bash","label":"npm"},{"cmd":"yarn add http-call","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-call","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Use ESM `import` for modern Node.js projects with `type: \"module\"` in `package.json` or `.mjs` files. The library provides dual CJS/ESM support.","wrong":"const { HTTP } = require('http-call')","symbol":"HTTP","correct":"import { HTTP } from 'http-call'"},{"note":"Use CommonJS `require` for older Node.js projects or environments without ESM support. Attempting to `require` an ESM module will result in `ERR_REQUIRE_ESM`.","wrong":"import { HTTP } from 'http-call'","symbol":"HTTP (CommonJS)","correct":"const { HTTP } = require('http-call')"},{"note":"For TypeScript, leverage generics to strongly type the response body, enhancing type safety and developer experience. The library ships with built-in type declarations.","wrong":"import { HTTP } from 'http-call';\n// Incorrect: Type not specified\nconst { body: user } = await HTTP.get('/users/me')","symbol":"HTTP (TypeScript with generics)","correct":"import { HTTP } from 'http-call';\n\ninterface User { id: string; email: string; name: string; }"}],"quickstart":{"code":"import { HTTP } from 'http-call';\n\ninterface GitHubUser {\n  login: string;\n  id: number;\n  node_id: string;\n  avatar_url: string;\n  name: string;\n  email: string | null;\n  bio: string | null;\n}\n\nasync function getGitHubUser(username: string): Promise<GitHubUser> {\n  try {\n    const token = process.env.GITHUB_TOKEN ?? ''; // Use environment variable for auth\n    if (!token) {\n      console.warn('GITHUB_TOKEN environment variable is not set. Requests may be unauthenticated or rate-limited.');\n    }\n\n    const { body: user } = await HTTP.get<GitHubUser>(`https://api.github.com/users/${username}`, {\n      headers: { authorization: token ? `token ${token}` : '' }\n    });\n    console.log(`Successfully fetched user ${user.name || user.login}. ID: ${user.id}, Bio: ${user.bio || 'N/A'}`);\n    return user;\n  } catch (error: any) {\n    console.error(`Error fetching GitHub user ${username}:`, error.message);\n    throw error;\n  }\n}\n\n// Example usage:\n(async () => {\n  try {\n    const myUser = await getGitHubUser('octocat');\n    console.log('GitHub User Details:', myUser);\n  } catch (e) {\n    // Error handled in getGitHubUser\n  }\n  try {\n    // Example with a non-existent user to demonstrate error handling\n    await getGitHubUser('nonexistentuser12345');\n  } catch (e) {\n    // Expected error, already logged\n  }\n})();","lang":"typescript","description":"This quickstart demonstrates how to make a GET request to the GitHub API, handling authentication, automatic JSON parsing, and TypeScript type inference for the response body. It includes error handling and shows how to use environment variables for sensitive data."},"warnings":[{"fix":"Review your application's network call expectations. If a longer or infinite timeout is required, explicitly set the `timeout` option in your request configuration: `HTTP.get('/slow-api', { timeout: 60000 })` for 60 seconds or `timeout: 0` for no timeout.","message":"Starting with v5.4.0, `http-call` introduced a default timeout for requests. Previously, requests might have waited indefinitely. This change can affect applications that relied on long-running or unbounded HTTP requests, potentially causing unexpected timeouts.","severity":"gotcha","affected_versions":">=5.4.0"},{"fix":"Standardize on a single module system across your application. For new projects, prefer ES Modules (set `\"type\": \"module\"` in `package.json`). If using CommonJS, ensure all imported packages are compatible or use dynamic `await import()` for ESM-only dependencies.","message":"While `http-call` supports both CommonJS (`require`) and ES Modules (`import`), mixing them incorrectly in a single project can lead to `ERR_REQUIRE_ESM` errors. Node.js's module resolution for interop can be complex.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Always use `await` with `HTTP` calls within an `async` function, or chain `.then()` and `.catch()` appropriately to handle both successful responses and errors. Ensure all asynchronous code paths are robustly handled to prevent unexpected application crashes.","message":"The library primarily operates on `Promise`s. While this is standard for modern JavaScript, improperly handling asynchronous operations (e.g., forgetting `await` or `.catch()`) can lead to unhandled promise rejections or incorrect control flow, especially when integrating with older callback-based code.","severity":"gotcha","affected_versions":">=5.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"If your project is ES Module-based, use `import { HTTP } from 'http-call'`. If your project is CommonJS, ensure your bundler/TypeScript configuration is correctly set up to consume dual-package formats, or ensure you are on a Node.js version that properly handles CJS-importing-ESM interop (typically Node.js 12.20+ or 14.13+ with `--experimental-json-modules` flag, though general CJS `require` of ESM is still a hard error without dynamic `import()`). The most reliable fix is to migrate to ESM if possible or use dynamic imports.","cause":"Attempting to use `require()` to load `http-call` in an environment where it's treated as an ES Module, typically in a CommonJS context.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/http-call/dist/index.js not supported."},{"fix":"Ensure you are correctly destructuring `HTTP` from the module: `import { HTTP } from 'http-call'` or `const { HTTP } = require('http-call')`. If it's still failing, check if another package named `http-call` is accidentally being imported or if the installation is corrupted.","cause":"This usually indicates incorrect destructuring of the import or attempting to call a method on an undefined or improperly imported object.","error":"TypeError: HTTP.get is not a function"},{"fix":"Ensure all options passed to `HTTP` methods or the configuration object conform to the expected TypeScript types. For `timeout`, provide a `number` representing milliseconds or `0` for no timeout: `await HTTP.get(url, { timeout: 5000 })`.","cause":"When using TypeScript, providing a non-numeric value to the `timeout` option (or other configuration options expecting specific types) will cause a type error.","error":"TS2345: Argument of type 'string' is not assignable to parameter of type 'number | undefined'."}],"ecosystem":"npm"}