Downloading: {{ downloadProgress }}%
```
### CORS and Credentials
```typescript
const { data } = api.listPets.useQuery({
axiosOptions: {
withCredentials: true, // Include cookies in cross-origin requests
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
},
})
```
### Proxy Configuration
```typescript
const { data } = api.listPets.useQuery({
axiosOptions: {
proxy: {
protocol: 'http',
host: 'proxy.example.com',
port: 8080,
auth: {
username: 'proxyuser',
password: 'proxypass',
},
},
},
})
```
### Response Validation
```typescript
const { data } = api.listPets.useQuery({
axiosOptions: {
// Accept 200-299 as success
validateStatus: (status) => status >= 200 && status < 300,
// Or custom logic
validateStatus: (status) => {
return status === 200 || status === 201 || status === 204
},
},
})
```
### Response Configuration
```typescript
const { data } = api.listPets.useQuery({
axiosOptions: {
responseType: 'json',
responseEncoding: 'utf8',
maxContentLength: 2000, // Max response body size
maxBodyLength: 1000, // Max request body size
},
})
```
### Redirect Configuration
```typescript
const { data } = api.listPets.useQuery({
axiosOptions: {
maxRedirects: 5, // Maximum number of redirects
decompress: true, // Automatic decompression
},
})
```
## Custom Properties
The `AxiosRequestConfigExtended` type supports arbitrary custom properties beyond standard Axios options. This is useful for:
- Custom error handling middleware
- Request tracking and logging
- Custom retry logic
- Request metadata for analytics
### Basic Custom Properties
```typescript
const { data } = api.listPets.useQuery({
axiosOptions: {
// Standard Axios options
timeout: 5000,
headers: { 'X-Custom-Header': 'value' },
// Custom properties
manualErrorHandling: true,
handledByAxios: false,
customRetryCount: 3,
debugMode: true,
},
})
```
### Complex Custom Properties
```typescript
const { data } = api.listPets.useQuery({
axiosOptions: {
timeout: 5000,
// Request metadata
requestMetadata: {
requestId: 'req-123',
source: 'list-pets',
userId: 'user-456',
},
// Custom error handling
manualErrorHandling: (error: unknown) => {
console.log('Handling error:', error)
return false // Let Axios handle it
},
// Custom retry strategy
customRetryStrategy: {
maxRetries: 3,
backoffFactor: 2,
retryableStatuses: [408, 429, 500, 502, 503, 504],
},
// Logging configuration
loggingConfig: {
logLevel: 'debug',
includeHeaders: true,
includeBody: false,
includeTiming: true,
},
// Request tracking
requestTrackingId: 'track-456',
},
})
```
### Using Custom Properties with Interceptors
You can access custom properties in Axios interceptors:
```typescript
// In your API initialization
import axios from 'axios'
const apiClient = axios.create({
baseURL: 'https://api.example.com',
})
apiClient.interceptors.request.use((config) => {
// Access custom properties
if (config.manualErrorHandling) {
console.log('Manual error handling enabled')
}
if (config.loggingConfig) {
console.log(`[${config.loggingConfig.logLevel}] Request to ${config.url}`)
}
if (config.requestMetadata) {
config.headers['X-Request-ID'] = config.requestMetadata.requestId
config.headers['X-Request-Source'] = config.requestMetadata.source
}
return config
})
// Use in queries
const { data } = api.listPets.useQuery({
axiosOptions: {
manualErrorHandling: true,
loggingConfig: {
logLevel: 'info',
includeHeaders: true,
},
requestMetadata: {
requestId: generateRequestId(),
source: 'list-pets',
},
},
})
```
## Merging Behavior
### Hook-Level vs Call-Level Options
For mutations, you can set axios options at hook time and override them at call time:
```typescript
const createPet = api.createPet.useMutation(
{},
{
axiosOptions: {
timeout: 5000,
headers: {
'X-Setup-Header': 'setup-value',
'Content-Type': 'application/json',
},
},
},
)
// Override at call time
await createPet.mutateAsync({
data: { name: 'Fluffy' },
axiosOptions: {
timeout: 10000, // Override setup timeout
headers: {
'X-Call-Header': 'call-value', // Additional header
'Content-Type': 'application/xml', // Override Content-Type
},
},
})
```
**Merging rules:**
- Call-level options override hook-level options
- Headers are merged (call-level headers override hook-level headers for same keys)
- All other properties are completely replaced by call-level options
### Lazy Query Merging
For lazy queries, you can set axios options at hook time and override them in fetch():
```typescript
const query = api.listPets.useLazyQuery({
axiosOptions: {
timeout: 5000,
headers: { 'X-Hook-Level': 'value' },
},
})
// Override at fetch time
await query.fetch({
queryParams: { limit: 10 },
axiosOptions: {
timeout: 10000, // Override
headers: { 'X-Fetch-Level': 'value' }, // Additional
},
})
```
## Common Patterns
### Per-Request Authentication Token
```typescript
const getAuthToken = () => {
return localStorage.getItem('authToken') || ''
}
const { data } = api.listPets.useQuery({
axiosOptions: {
headers: {
Authorization: `Bearer ${getAuthToken()}`,
},
},
})
```
### Reactive Authentication
```typescript
const authToken = ref