The base URL for all requests. This is prepended to the request path when making requests.
Optional
credentialsCredentials mode for requests.
Default headers to include in every request. These headers will be merged with any headers provided in individual requests.
Interceptors for modifying requests and responses. This object provides methods to register request and response interceptors.
Number of times to retry failed requests. If a request fails, it will be retried this many times before throwing an error.
Default timeout for requests in milliseconds. If a request takes longer than this time, it will be aborted.
Performs a DELETE request.
The request path.
Optional request configuration.
A Promise resolving to the Response.
Downloads a file while reporting progress.
The request path.
Callback for download progress.
Optional request configuration.
A Promise resolving to the downloaded Blob.
fetcher.downloadWithProgress('/file.zip', (loaded, total) => {
const percentComplete = total ? (loaded / total) * 100 : 0;
console.log(`Download progress: ${percentComplete}%`);
})
.then(blob => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'file.zip';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
})
.catch(err => console.error(err));
Performs a GET request and parses JSON.
The request path.
Optional request configuration.
A Promise resolving to the Response.
Performs a POST request with a JSON body.
The request path.
The JSON payload.
Optional request configuration.
A Promise resolving to the Response.
Performs a POST request with upload progress reporting using XHR.
The request path.
The payload to upload.
Callback for upload progress.
Optional request configuration.
A Promise resolving to the Response.
Performs a PUT request with a JSON body.
The request path.
The JSON payload.
Optional request configuration.
A Promise resolving to the response.
Performs a raw HTTP request.
The request path relative to baseURL.
Request configuration.
A Promise resolving to the Response object.
Fetcher is a universal HTTP client that supports fetch and XHR fallback. It provides methods for making requests, handling responses, and managing interceptors. It supports automatic retries, timeouts, and progress reporting for downloads and uploads.
Example