/** * HTTP utilities for making requests with common patterns. */ /** * Options for creating an HTTP client. */ export interface HttpClientOptions { /** Custom fetch implementation (defaults to global fetch) */ fetchImpl?: typeof fetch; /** Default headers to include in all requests */ defaultHeaders?: Record; } /** * Ensures fetch is available in the current environment. * @remarks * This returns a thin wrapper around the global `fetch` so the call site has a stable function type. * @throws If `fetch` is not available in the current environment (e.g. older Node.js without polyfill). */ export declare function ensureFetch(): typeof fetch; /** * Normalizes a base URL to ensure it ends with a slash. */ export declare function normalizeBaseUrl(url: string): string; /** * Builds a full URL from a base URL and a path. */ export declare function buildUrl(baseUrl: string, path: string): string; /** * Wraps a fetch error with context about the request. */ export declare function wrapFetchError(url: string, error: unknown, context?: string): Error; /** * Merges multiple header sources into a single Record. * Handles HeadersInit types: Record, Headers, or [string, string][]. */ export declare function mergeHeaders(...sources: (HeadersInit | undefined)[]): Record; /** * Options for individual fetch requests. */ export type FetchOptions = RequestInit; /** * A reusable HTTP client with common patterns. */ export declare class HttpClient { private readonly fetchFn; private readonly defaultHeaders; readonly baseUrl: string; constructor(baseUrl: string, options?: HttpClientOptions); /** * Builds a full URL from a relative path. */ url(path: string): string; /** * Makes a fetch request with error handling. */ fetch(path: string, options?: FetchOptions): Promise; /** * Makes a fetch request and throws if the response is not ok. * @remarks * - This does not consume the response body. Callers can still read `.json()`, `.text()`, etc. * - The thrown error message is intentionally stable for tests and debugging: * `request to failed with status `. */ fetchOk(path: string, options?: FetchOptions): Promise; /** * Makes a GET request and returns JSON. */ getJson(path: string, options?: FetchOptions): Promise; /** * Makes a POST request with JSON body and returns the Response (does not parse body). * Use this when you only need to verify the request succeeded. */ postOk(path: string, body: T, options?: FetchOptions): Promise; } //# sourceMappingURL=http.d.ts.map