createFetchClient function creates a new callApi instance with custom default configuration. This is useful for creating clients with shared settings like base URLs, headers, authentication, and hooks.
Function Signature
Parameters
Base configuration applied to all requests made with this client. Can be an object or a function that returns configuration dynamically.
Static Configuration
Dynamic Configuration
Configuration Options
All options fromcallApi are supported, plus:Controls how base config merges with per-request config:
undefined: Auto-merge both options and request'options': Don’t merge CallApi-specific options'request': Don’t merge fetch request options'all': Don’t merge anything (per-request config fully overrides)
Array of plugins to extend client functionality.
Return Type
Returns a
callApi function with the base configuration pre-applied. The returned function has the same signature as the standalone callApi function.Usage Examples
Basic Client with Base URL
Client with Authentication
Dynamic Configuration Function
Client with Default Error Handling
Client with Retry and Timeout
Multiple Clients for Different APIs
Client with Request/Response Logging
Overriding Base Configuration
Client with Schema Validation
Type Inference
The created client inherits all type inference capabilities:Best Practices
- Create clients per API domain: Separate clients for different APIs or services
- Use dynamic config for auth: Update tokens without recreating the client
- Set sensible defaults: Configure timeouts, retries, and error handling once
- Add logging in development: Use hooks to debug requests and responses
- Type your responses: Always provide TypeScript types for type safety
Related
- callApi - Default client instance
- createFetchClientWithContext - Create client with custom context types