rxnet_plus 0.7.0
rxnet_plus: ^0.7.0 copied to clipboard
Flexible network request framework with pluggable adapters (Dio, http, or custom), supporting various caching strategies
0.7.0 #
New Features #
-
RxNetConfig Configuration Class - Clean, type-safe configuration with Builder pattern
RxNetConfigreplaces long parameter lists with a structured config object- Builder pattern:
RxNetConfig.builder().baseUrl('...').cacheMode(...).build() copyWith()for immutable config modifications- 100% backward compatible - old
initNet()parameters still work
-
Cache Eviction Policies - Automatic cache size management
cacheMaxSize- Maximum number of cache entries (0 = unlimited)CacheEvictionPolicy.lru- Least Recently Used evictionCacheEvictionPolicy.lfu- Least Frequently Used evictionCacheEvictionPolicy.fifo- First In First Out evictionCacheMetadatatracks createdAt, lastAccessedAt, accessCount per entry- Automatic eviction on every cache write when size exceeds limit
-
RetryPolicy - Advanced retry strategies beyond fixed interval
RetryStrategy.fixed- Fixed interval (default, backward compatible)RetryStrategy.exponentialBackoff- Delay doubles each attemptRetryStrategy.exponentialBackoffWithJitter- Exponential + random jittermaxIntervalcap to prevent excessive delays- Factory methods:
RetryPolicy.fixed(),RetryPolicy.exponentialBackoff(),RetryPolicy.exponentialBackoffWithJitter()
-
AdapterBaseOptions - Adapter-agnostic global request defaults
- Set connectTimeout, receiveTimeout, sendTimeout globally
- Set default headers, contentType, responseType
- Configurable followRedirects, maxRedirects, persistentConnection
- Applied via
RxNetConfig(adapterBaseOptions: ...)or Builder
-
TokenRefreshInterceptor - Automatic token refresh on auth errors
- Detects 401/403 responses and triggers token refresh
- Concurrent refresh deduplication (only one refresh call at a time)
- Customizable
isUnauthorizedcallback onRequestUpdatedcallback to inject new token into request- Lifecycle callbacks:
onTokenRefreshing,onTokenRefreshed,onTokenRefreshFailed
-
DeduplicateInterceptor - Request deduplication within time window
- Prevents duplicate requests with same path within configurable window
- Automatically allows requests after window expires
-
ThrottleInterceptor - Request rate limiting
- Rejects requests within throttle window after the first pass-through
- Configurable throttle duration
-
Cache Clearing by Prefix/Pattern - Granular cache management
cacheManager.clearByPrefix(prefix)- Clear all entries matching prefixcacheManager.clearByPattern(pattern)- Clear all entries matching regex
-
RxResult Improvements - Safer result handling
RxResult.success(value)factory - Guaranteed non-null valuerequiredValuegetter - Throws StateError if error or null
Improved #
- BuildRequest Cache Integration - Cache operations now use
RxNetCachedirectly- Cache reads/writes go through
RxNetCache.saveNetworkCache()/readNetworkCache() - Eviction policies enforced automatically on cache writes
- Cache reads/writes go through
Changed #
- Database Metadata Store -
RxNetDataBasenow supports metadata storageputMetadata()/getMetadata()/deleteMetadata()/getAllMetadata()/cleanMetadata()- Separate Sembast store for cache metadata (eviction tracking)
Migration Guide #
100% backward compatible - No code changes required. New features are opt-in.
New: RxNetConfig (recommended)
Before:
await RxNet.init(
baseUrl: "https://api.example.com",
cacheMode: CacheMode.CACHE_EMPTY_OR_EXPIRED_THEN_REQUEST,
cacheInvalidationTime: 60000,
interceptors: [RxNetLogAdapterInterceptor()],
);
After:
await RxNet.init(config: RxNetConfig(
baseUrl: "https://api.example.com",
cacheMode: CacheMode.CACHE_EMPTY_OR_EXPIRED_THEN_REQUEST,
cacheInvalidationTime: 60000,
interceptors: [RxNetLogAdapterInterceptor()],
cacheMaxSize: 500,
cacheEvictionPolicy: CacheEvictionPolicy.lru,
adapterBaseOptions: AdapterBaseOptions(
connectTimeout: Duration(seconds: 10),
receiveTimeout: Duration(seconds: 30),
),
));
New: RetryPolicy
Before:
RxNet.get()
.setPath("/api/data")
.setRetryCount(3, interval: Duration(seconds: 2))
.request();
After:
RxNet.get()
.setPath("/api/data")
.setRetryPolicy(RetryPolicy.exponentialBackoff(
maxRetries: 3,
baseInterval: Duration(seconds: 1),
maxInterval: Duration(seconds: 10),
))
.request();
0.6.2 #
0.6.1 #
New Features #
- Concurrent Callback Requests - Execute multiple callback-based requests in parallel
- Sembast Database - Replaced Hive with pure Dart database solution
Fixed #
- Breakpoint Download Fixes - Works correctly with all adapters
- HttpAdapter Improvements - Multipart upload, stream responses, progress tracking
- URL Path Normalization - Fixed multiple slashes in request URLs
- Web Platform Support - Fixed adapters on Web platform
0.6.0 #
Added #
- Pluggable Adapter Architecture - DioAdapter, HttpAdapter, MockAdapter
- Unified Interceptor System - Adapter-agnostic AdapterInterceptor interface
- Custom Adapter Support - Implement NetworkAdapter interface
0.5.0 #
- Parameter type separation - Path, query, and body parameters
- RESTful automatic detection - No manual settings required
- API semantic improvement - More intuitive method names
- Low-level reconstruction - Updated BuildRequest
0.4.x #
- Generic request support with type conversion
- RESTFul @path style request support
- Overall architecture redesign