Outcome Recipes
Scenario-based patterns for @aurelia/fetch-client that solve common API challenges like auth, caching, and uploads.
1. Token-aware API client with automatic retries
Steps
import { IHttpClient } from '@aurelia/fetch-client'; import { resolve } from '@aurelia/kernel'; const http = resolve(IHttpClient); http.configure(config => config .withBaseUrl('https://api.example.com/') .withDefaults({ headers: { 'Content-Type': 'application/json' } }) .withRetry({ maxRetries: 3, strategy: RetryStrategy.exponential, interval: 2000, doRetry: (error) => error.status >= 500 }) .withInterceptor({ request(request) { request.headers.set('Authorization', `Bearer ${tokenStore.current}`); return request; }, async responseError(error, request, client) { if (error.status === 401) { await tokenStore.refresh(); return client.fetch(request); } throw error; } }) .rejectErrorResponses() );
Checklist
2. Stale-while-revalidate dashboards
Steps
Checklist
3. Abortable uploads with progress feedback
Steps
Checklist
4. Time-boxed requests with automatic timeout
Steps
Checklist
5. Correlated requests with logging
Steps
Checklist
Pattern picker
Outcome
Key APIs
Last updated
Was this helpful?