🤝 All Options
Complete guide to instance configuration options and request-level settings.
Z-Fetch provides comprehensive configuration options that can be set at the instance level for consistent behavior across all requests, or at the request level for specific customization.
Instance Configuration
Set default options when creating an instance:
Core Configuration Options
Base URL
Set a base URL for all requests:
Headers
Set default headers for all requests:
Headers are intelligently merged:
Authentication
Bearer Token
Automatic Bearer token authentication:
Basic Authentication
API Key Authentication
Credentials and CORS
Control how credentials are sent with requests:
- Fetch path: sets
credentials: 'include'. - XHR path (when using progress callbacks): sets
xhr.withCredentials = true.
Advanced Configuration
Timeout
Set request timeout in milliseconds:
Retry Configuration
Configure automatic retries for failed requests:
Cache Configuration
Control request and response caching:
- Successful GET responses are cached when
withCache: true. - Failed or canceled GETs are not cached; the next call hits the network.
- Background revalidation preserves existing cache on failure.
Progress Tracking Configuration
Upload Progress
Download Progress
Error Configuration
Error Handling Mode
Choose how errors are handled - returned in result or thrown:
Choose Your Style
throwOnError: false (default) is safer and more explicit. throwOnError: true is familiar for developers from fetch/axios. Both work with all features.
Error Mapping
Map errors to user-friendly text. By default, only z-fetch internal errors are mapped:
Optionally enable mapping for backend HTTP errors:
Backend Error Mapping is Optional
By default (mapErrors: false), only z-fetch internal errors (NETWORK_ERROR, TIMEOUT, CANCELED) are mapped. Set mapErrors: true to also map backend HTTP status codes.
Error Handling Hook
Request/Response Processing
JSON Handling
Control automatic JSON parsing:
Response Processing
Environment-Based Configuration
Development vs Production
Configuration Loading
Complete Configuration Example
Request-Level Overrides
Any instance configuration can be overridden at the request level:
Configuration Priority
Request-level options always take precedence over instance-level options.