- Type-safe requests/responses
- Interceptors for auth, headers, retry, and logging
- Error mapping to app-friendly types
- Configurable retry (exponential backoff)
- Optional response caching
Full technical details live in your project at
/docs/modules/Networking.md.Purpose
Handles:- HTTP requests via a single
HTTPClientAPI - Cross-cutting concerns (auth tokens, headers, retry, logging)
- Consistent error handling and recoverability
Core Abstractions
HTTPClient Protocol
Request Pattern (example)
Interceptors (overview)
Interceptors (overview) Auth: Injects Authorization: Bearer … using a Keychain-backed token provider (no manual header work). Retry: Exponential backoff with jitter; respects Retry-After; retries only idempotent methods. Headers: Adds stable app metadata and any custom headers. Logging: Pluggable diagnostics (disabled in release by default).Configuration is done in your app’s composition layer. See /docs/modules/Networking.md for wiring examples.
What This Gives You
- Automatic Authentication
- Intelligent Retry
- Consistent Headers
KeychainTokenProvider + AuthInterceptorEvery HTTP request automatically includes auth token:
- ✅ Reads token from secure iOS Keychain
- ✅ Adds
Authorization: Bearer {token}header - ✅ Only if not already present (respects manual overrides)
- ✅ Returns nil gracefully if no token stored
- ✅ Thread-safe and tested
Real Production Value
This isn’t a simple example - it’s battle-tested production code:- ✅ Secure: Tokens in iOS Keychain (not UserDefaults)
- ✅ Tested: Comprehensive unit tests included
- ✅ Resilient: Auto-retry with backoff
- ✅ Maintainable: Clean separation of concerns
- ✅ Extensible: Easy to add custom interceptors
Customization Examples
Add Custom Request
Add Custom Interceptor
Configuration
Setup in CompositionRoot
Error Handling
All HTTP errors are mapped toAppError:
Key Files
| Component | Location |
|---|---|
| HTTPClient | Packages/Networking/Sources/Networking/HTTPClient.swift |
| Interceptors | Packages/Networking/Sources/Networking/Interceptors/ |
| Retry Logic | Packages/Networking/Sources/Networking/Retry/ |
Dependencies
- Core - Error handling, logging
Used By
- Auth - API calls to Supabase
- AI - Proxy requests
- Custom services - Your API calls
Best Practices
Request Design
Request Design
- One struct per endpoint
- Type-safe responses
- Encodable request bodies
- Clear naming (verb + noun)
Error Handling
Error Handling
- Map to AppError
- Retry idempotent requests
- Log failures with context
- Provide user-friendly messages
Interceptors
Interceptors
- Order matters (auth before retry)
- Keep interceptors focused
- Test in isolation
- Use for cross-cutting concerns
Learn More
Full Documentation
Find complete technical guides inside your project under /docs/modules/Networking.md.
Auth Module
Uses HTTPClient for API calls
AI Module
Uses HTTPClient for proxy
Architecture
See networking layer
Test Coverage
93%+ - Comprehensive test suite Tests include:- Request execution
- Interceptor ordering
- Retry logic
- Error scenarios
- Timeout handling
