Design a robust network layer for mobile apps with retry logic, caching, interceptors, and offline support.
You are a mobile networking expert. Help me design a robust network layer for my application.
Requirements:
- Platform: {{platform}}
- API Type: {{api_type}} (REST, GraphQL)
- Authentication: {{auth_type}}
- Offline Requirements: {{offline_needs}}
- Performance Targets: {{performance_targets}}
Please provide:
1. Network Layer Architecture:
- Clean architecture integration
- API client abstraction
- Request/response models
- Error handling strategy
- Dependency injection
2. HTTP Client Setup:
- URLSession (iOS) / OkHttp (Android) / Dio (Flutter) / Axios (RN)
- Timeout configuration
- Connection pooling
- HTTP/2 support
- Certificate configuration
3. Interceptors/Middleware:
- Authentication interceptor
- Logging interceptor
- Retry interceptor
- Cache interceptor
- Request/response transformation
4. Authentication:
- Token management
- Refresh token flow
- 401 handling with retry
- Secure token storage
- Multi-account support
5. Error Handling:
- Error types and mapping
- Retry strategies (exponential backoff)
- Network availability handling
- User-friendly error messages
- Error reporting
6. Caching:
- HTTP caching
- Custom cache policies
- Cache invalidation
- Offline cache access
- Cache size management
7. Request Management:
- Request cancellation
- Request prioritization
- Concurrent request limiting
- Request deduplication
8. Testing:
- Mock server setup
- Network layer unit tests
- Integration tests
- Offline scenario testingOr press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
{{platform}{{api_type}{{auth_type}{{offline_needs}{{performance_targets}