v1.4.2

Advanced Usage

Because BoltFetch is a direct layer over the native fetch API, it supports complex HTTP patterns gracefully.

Response Type Parsing

By default, BoltFetch assumes the server is returning JSON, and will automatically attempt to parse it. If you need to download raw text, HTML, or binary data (like an image or PDF), you can specify the responseType in the configuration.

Text Response

typescript
const response = await boltfetch.get("/robots.txt", { responseType: "Text" }); if (response.success) { console.log("Raw text:", response.data); }

Blob (Binary) Response

typescript
const response = await boltfetch.get("/images/logo.png", { responseType: "Blob" }); if (response.success) { // response.data is a Blob object const url = URL.createObjectURL(response.data); const img = document.createElement("img"); img.src = url; document.body.appendChild(img); }

ArrayBuffer Response

typescript
const response = await boltfetch.get("/data/binary-file", { responseType: "ArrayBuffer" }); if (response.success) { // response.data is an ArrayBuffer const view = new DataView(response.data); console.log(view.getInt32(0)); }

Form Data & File Uploads

BoltFetch natively supports the FormData object. When you pass a FormData instance as the body of a POST or PUT request, BoltFetch will handle it correctly without attempting to serialize it to JSON.

Note: You do not need to set the Content-Type header when sending FormData; the browser will automatically set it to multipart/form-data with the correct boundary.

typescript
const uploadFile = async (file: File) => { const formData = new FormData(); formData.append("document", file); formData.append("userId", "123"); const response = await boltfetch.post('/upload', formData); if (response.success) { console.log("Upload complete!"); } }

Next.js Integration

BoltFetch works perfectly in Next.js. Since Next.js aggressively patches the global fetch API to provide caching, using BoltFetch means you inherit those caching capabilities.

You can pass Next.js specific fetch options via the config object if needed, although BoltFetch abstracts most standard use cases cleanly.