createHttpClient
Creates a fully-typed HTTP client with built-in deduplication, retries, and auth handling.
const client = createHttpClient(config)
Config Options
| Property | Type | Default | Description |
|---|---|---|---|
baseURL | `string` | - | Root URL for requests. |
timeout | `number` | `10000` | Timeout in ms. |
headers | `object` | - | Default headers. |
retry | `number | object` | - | Retry logic configuration. |
auth | `AuthConfig` | - | Token management logic. |
AuthConfig
| Property | Type | Description |
|---|---|---|
getToken | `() => string | Promise<string>` | Function to retrieve the token (e.g., from localStorage). |
onTokenExpired | `() => Promise<string>` | Function called on 401. Should refresh token and return new one. |
onAuthFailed | `() => void` | Called if refresh fails. |
Methods
get<T>(url, config)post<T>(url, data, config)put<T>(url, data, config)delete<T>(url, config)patch<T>(url, data, config)
Deduplication
GET requests to the same URL with the same parameters are automatically deduplicated if they happen simultaneously.