API Reference
This document provides exhaustive details on the types, interfaces, and methods exposed by the boltfetch module.
Core Client Creation
configureBoltFetchClient(config)
Creates and returns a new configured BoltFetch instance.
Parameters:
config(Object): The configuration object.baseUrl(string): Pre-pended to all relative request paths.globalConfig(globalRequestConfig): Default configurations applied to every request.requestInterceptor(Function): A hook that receives theconfigbefore execution. Must return the modifiedconfig.responseInterceptor(Function): A hook that receives the rawresponseobject. Must return the response.
Request Methods
The default boltfetch instance and any instance created via configureBoltFetchClient share the exact same method signatures.
All methods return a Promise resolving to a union type: BoltFetchResponse<T> | BoltFetchError.
get<T>(url: string, config?: globalRequestConfig)
Initiates a GET request.
post<T>(url: string, body?: any, config?: globalRequestConfig)
Initiates a POST request. The body is automatically stringified to JSON (unless it's FormData).
put<T>(url: string, body?: any, config?: globalRequestConfig)
Initiates a PUT request.
patch<T>(url: string, body?: any, config?: globalRequestConfig)
Initiates a PATCH request.
delete<T>(url: string, config?: globalRequestConfig)
Initiates a DELETE request.
Types & Interfaces
globalRequestConfig
Configuration overrides that can be applied globally or per-request.
| Property | Type | Description |
|---|---|---|
timeout | number | Time in milliseconds before the request is aborted using AbortController. |
headers | Record<string, string> | Custom HTTP headers. |
params | Record<string, any> | Query parameters to append to the URL (e.g. ?search=term). |
responseType | "Json" | "Text" | "Blob" | "ArrayBuffer" | Determines how BoltFetch parses the response body. |
BoltFetchResponse<T>
Returned when a request succeeds (response.ok is true).
| Property | Type | Description |
|---|---|---|
success | true | Always true for successful requests, used for type narrowing. |
status | number | The HTTP status code (e.g., 200, 201). |
statusText | string | The HTTP status text (e.g., "OK"). |
data | T | The parsed response payload. |
headers | Record<string, string> | Response headers returned by the server. |
config | Record<string, string> | The final configuration used to make the request. |
BoltFetchError
Returned when a request fails due to a network error, timeout, or a server error (!response.ok).
| Property | Type | Description |
|---|---|---|
success | false | Always false for failed requests, used for type narrowing. |
status | number | The HTTP status code. Might be 0 or undefined on network/timeout errors. |
message | string | Human-readable error message. |
url | string | The URL that was requested. |
method | string | The HTTP method used. |
moreInfo | any | The parsed response payload (if any was returned by the server along with the error). |