Configuration
BoltFetch is designed to be flexible. You can use the default global boltfetch object for quick requests, or configure custom clients for complex applications.
Custom Client Configuration
To configure a client, use configureBoltFetchClient.
typescriptimport { configureBoltFetchClient } from "boltfetch"; const apiClient = configureBoltFetchClient({ baseUrl: "https://api.example.com/v1", globalConfig: { timeout: 10000, // 10 seconds global timeout headers: { "Accept": "application/json", "X-App-Version": "1.0.0" }, responseType: "Json" } }); // apiClient now has 'get', 'post', 'put', 'patch', 'delete'
Timeouts
By default, the native fetch API does not have a timeout. BoltFetch adds native timeout support using AbortController.
If a request exceeds the specified timeout in milliseconds, the request is aborted and a BoltFetchError is returned.
Per-Request Overrides
You can override the global configuration on a per-request basis by passing a configuration object as the final argument.
typescriptconst response = await apiClient.get('/reports/heavy-export', { timeout: 30000, // Override to 30 seconds for this slow endpoint headers: { "Cache-Control": "no-cache" }, params: { format: "csv" // Automatically appends ?format=csv } });
Query Parameters
BoltFetch provides a convenient params object in the request configuration. You do not need to manually construct query strings.
typescriptconst response = await apiClient.get("/search", { params: { query: "typescript", page: 2, active: true } }); // Automatically requests: /search?query=typescript&page=2&active=true
Response Types
You can tell BoltFetch how to parse the incoming response using responseType.
Available options: "Json" | "Text" | "Blob" | "ArrayBuffer".
(Default is "Json").
typescriptconst textResponse = await apiClient.get("/changelog.txt", { responseType: "Text" });