WeldRequestOptions
Every request method accepts an optional WeldRequestOptions object as the last argument.
Reference
Section titled “Reference”interface WeldRequestOptions { headers?: Record<string, string> query?: Record<string, string | number | boolean> body?: unknown schema?: ZodSchema offlineFallback?: boolean deduplicate?: boolean retry?: RetryOptions timeout?: number}Fields
Section titled “Fields”headers
Section titled “headers”Additional headers merged with the client-level defaults.
api.get('v1/products', Schema, { headers: { 'X-Tenant-ID': 'acme-corp' },})Query string parameters appended to the URL. All values are stringified automatically.
api.get('v1/products', Schema, { query: { page: 2, limit: 50, sort: 'price' },})// → GET /v1/products?page=2&limit=50&sort=priceRequest body for POST, PUT, and PATCH. Serialized as JSON automatically.
api.post('v1/products', Schema, { body: { name: 'Widget', price: 9.99 },})offlineFallback
Section titled “offlineFallback”Enable or disable IndexedDB cache fallback for GET requests, or mutation queuing for POST/PUT/PATCH/DELETE.
Default: true for all requests.
api.get('v1/products', Schema, { offlineFallback: false })deduplicate
Section titled “deduplicate”Deduplicate concurrent in-flight requests with the same cache key.
Default: true for GET requests.
api.get('v1/products', Schema, { deduplicate: false })Override the global retry configuration for this specific request.
api.get('v1/products', Schema, { retry: { attempts: 5, delay: 1000, condition: (err) => err instanceof WeldNetworkError && err.status >= 500, },})timeout
Section titled “timeout”Request timeout in milliseconds. Overrides the client-level default.
api.get('v1/heavy-report', Schema, { timeout: 30_000 })RetryOptions
Section titled “RetryOptions”interface RetryOptions { attempts: number // retry attempts after first failure delay: number // base delay in ms (exponential backoff) condition?: (err: Error) => bool // return false to skip retry for this error}Backoff formula: delay * 2^attempt
| Attempt | Delay (base: 300ms) |
|---|---|
| 1st retry | 300ms |
| 2nd retry | 600ms |
| 3rd retry | 1200ms |
