util-http is a JavaScript and TypeScript utility library designed to simplify and standardize HTTP requests by providing a unified API layer over several popular underlying HTTP clients. It currently supports wrapping `Axios`, the native `Fetch API`, `Undici` for high-performance Node.js environments, and `Superagent` for isomorphic (Node.js and browser) use cases. The library is currently in an early development phase, at version 0.0.15, implying a potentially rapid release cadence with possible breaking changes between minor versions. Its primary differentiator is the ability to swap out the underlying HTTP client while maintaining a consistent `ClientConfig` for global settings and `ClientOptions` for per-request overrides, complete with robust TypeScript type definitions for enhanced developer experience. It aims to abstract away client-specific configurations and error handling into a standardized interface, allowing developers to choose their preferred backend client without changing their application's request logic.
npm install util-httpVerified import paths — ran on the pinned version, not inferred.
Initializes an AxiosClient with global configurations, sets up an error interceptor, and performs a GET request to an API endpoint.
Refer to the GitHub repository's commit history and README for specific changes between versions. It is recommended to pin exact versions or conduct thorough testing when upgrading.
If using `AxiosClient`, run `npm install axios`. If using `UndiciClient`, run `npm install undici`. If using `SuperAgentClient`, run `npm install superagent`.
Always review the method signatures and documentation for `ClientConfig` and `ClientOptions` to ensure you are applying settings at the correct scope and precedence. Global headers, timeouts, and base URLs are set via `ClientConfig`, while specific URL, method, and data for a single request are set via `ClientOptions`.
Install `axios`: `npm install axios` or `pnpm add axios`.
Review the `ClientConfig` interface for expected property names and types. Ensure all properties conform to the interface definition.
Ensure the client object (e.g., `new AxiosClient(...)`) is correctly instantiated and assigned to a variable before attempting to make requests.