v1.4.2

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 the config before execution. Must return the modified config.
    • responseInterceptor (Function): A hook that receives the raw response object. 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.

PropertyTypeDescription
timeoutnumberTime in milliseconds before the request is aborted using AbortController.
headersRecord<string, string>Custom HTTP headers.
paramsRecord<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).

PropertyTypeDescription
successtrueAlways true for successful requests, used for type narrowing.
statusnumberThe HTTP status code (e.g., 200, 201).
statusTextstringThe HTTP status text (e.g., "OK").
dataTThe parsed response payload.
headersRecord<string, string>Response headers returned by the server.
configRecord<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).

PropertyTypeDescription
successfalseAlways false for failed requests, used for type narrowing.
statusnumberThe HTTP status code. Might be 0 or undefined on network/timeout errors.
messagestringHuman-readable error message.
urlstringThe URL that was requested.
methodstringThe HTTP method used.
moreInfoanyThe parsed response payload (if any was returned by the server along with the error).