sonic 1.3.0
sonic: ^1.3.0 copied to clipboard
A fluent interface for handling network requests.
1.3.0 - 2025-10-12 #
Interface-based Auth Refresh System with Custom Handler Support
Breaking changes:
-
AuthRefreshInterceptornow accepts anIAuthRefreshHandlerinterface instead of individual callback parameters. If you were manually creatingAuthRefreshInterceptorinstances (not common), wrap your callbacks inDefaultAuthRefreshHandler:// Before AuthRefreshInterceptor( shouldRefresh: (err) => err.response?.statusCode == 401, refresh: () async => token, setAuthHeader: (req, token) => req.headers['Authorization'] = 'Bearer $token', ) // After AuthRefreshInterceptor( handler: DefaultAuthRefreshHandler( shouldRefresh: (err) => err.response?.statusCode == 401, refresh: () async => token, setAuthHeader: (req, token) => req.headers['Authorization'] = 'Bearer $token', ), ) -
No changes needed if you use
SimpleAuthRefreshConfiginBaseConfiguration- it continues to work as before.
New/Improvements:
IAuthRefreshHandlerinterface - Implement custom auth refresh logic with full control:shouldRefresh(DioException)- Determine if refresh is neededrefreshToken()- Perform token refresh operationsetAuthHeader(RequestOptions, String)- Set authorization headeronRefreshSuccess(String)- Optional hook called after successful refreshonRefreshError(dynamic)- Optional hook called when refresh fails
DefaultAuthRefreshHandler- Default implementation using callback functions- Enhanced
SimpleAuthRefreshConfig- Added optionalonSuccessandonErrorcallbacks for lifecycle management - Better extensibility - Easily implement custom refresh logic with retry mechanisms, token persistence, logging, and automatic logout
- Improved testability - Mock
IAuthRefreshHandlerin tests instead of individual callbacks - Type safety - Interface ensures all required methods are implemented
Examples:
- Added
example/custom_auth_handler_example.dartdemonstrating all three approaches (SimpleAuthRefreshConfig, custom handler, DefaultAuthRefreshHandler) - Added
example/production_auth_handler_example.dartshowing production-ready implementation with:- Retry logic with exponential backoff
- Token persistence to secure storage
- Refresh loop prevention
- Automatic logout on permanent failure
- Refresh token rotation support
Docs:
- Updated
wiki/AuthRefresh.mdwith comprehensive examples of interface-based approach - Added
AUTH_REFRESH_REFACTORING.mdmigration guide - All existing examples and tests updated to use new API
Internal:
- All 71 tests pass with new implementation
- Backward compatibility maintained through
SimpleAuthRefreshConfig.toHandler() - Zero breaking changes for users of
SimpleAuthRefreshConfig
1.2.0 - 2025-10-12 #
Fluent API polish, Dockerized benchmarks, and docs refresh
Breaking changes:
- Fluent builder now uses consistent
withXnaming. The older non-withmethods (e.g.,get(),post(),cache(),deduplicate(),upload(),asMultipart(),pluck(),envelope(),strict(),onSuccess()/onError()/onLoading(), etc.) have been removed. Migrate to:- HTTP verb:
.withMethod(HttpMethod.get) - Raw request:
.withRawRequest() - Cache:
.withCache() - Deduplication:
.withDeduplication() - Uploads:
.withUpload(),.withMultipart(),.withField(),.withFields(),.withFiles(),.withFileFromPath(),.withFileFromBytes(),.withFileFromStream() - Shaping:
.withPluck(),.withEnvelope() - Strict/guards/adapters:
.withStrict(),.withTypeGuard(),.withSchemaAdapter() - Callbacks:
.withOnSuccess(),.withOnError(),.withOnLoading() - Redirects/limits:
.withFollowRedirects([bool]),.withMaxRedirects() - API versioning:
.withApiVersion('v2')
- HTTP verb:
New/Improvements:
- Public export of
HttpMethodfrompackage:sonic/sonic.dartfor cleaner usage in apps and examples. - Added Docker-based benchmark workflow and script
scripts/run_benchmarks_docker.ps1to run analyzer, tests, benchmarks, and optionally export results to the wiki. - New wiki page
Benchmarks.mdwith tabular results;benchmark/render_results.dartrenders Markdown andbenchmark/export_to_wiki.dartcopies it to your wiki folder. - Improved uploads API ergonomics with
withBinaryBodyandwithBodyStreamfor non-multipart uploads.
Docs:
- Updated README and wiki (Getting Started, Uploads, Decoding, Cookbook) to reflect
withXnaming. - README examples show
.withMethod(HttpMethod.get)and.withApiVersion('v2')patterns.
Internal/Tooling:
- Dockerfile and .dockerignore added for consistent CI/repeatable runs.
- Minor analyzer cleanups; tests remain green.
1.1.0 - 2025-10-12 #
New: Per-request API Versioning with placeholders and custom resolvers
- Per-request API version switching via
SonicRequestBuilder.useApiVersion('v2'). BaseConfiguration.apiVersionssupports placeholders:{baseUrl},{origin},{scheme},{host},{port},{basePath},{version}.- Custom placeholder resolver:
apiVersionPlaceholderResolver(name, arg, baseUri, version). - Optional environment-based resolution for
{env:NAME}(disabled by default):envPlaceholdersFromDartDefines: read fromString.fromEnvironment(NAME).envPlaceholdersFromProcessEnv: read fromPlatform.environment[NAME].
- URL resolution, caching/deduplication, and rate-limiting/circuit selection honor the resolved absolute URL.
- Download path and onRequest hooks use the effective baseUrl.
Docs
- README: Feature bullet, API Versioning section with placeholders.
- Wiki: API-Versioning page with configuration, placeholders, custom resolver, env flags, and examples.
Tests
- Added tests for
{baseUrl},{origin}/{version}, custom resolver, and general request wiring.
Internal
- Minor lint cleanups and consistency tweaks around control bodies and import ordering.
1.0.0 #
Major release with a production-ready, batteries-included HTTP client on top of Dio. Highlights:
- Safe decoding helpers: DecodeResult
- Typed builder API with cached decoders per type
- Retries with backoff+jitter and Retry-After support; 429 considered retryable
- Per-host rate limiting (token bucket) with RequestPriority (low/normal/high)
- Circuit breaker per-host (Closed/Open/HalfOpen) with event hooks
- Request templates registry for reusable presets
- Caching: in-memory LRU with TTL, SWR (stale-while-revalidate), ETag/Last-Modified validation and Expires fallback; optional composite/file stores
- Request deduplication for identical in-flight GETs
- Observability: response.extra includes timers (durationMs, networkMs, decodeMs, cacheLookupMs, cacheRevalidateMs, rateLimitWaitMs), retryDelaysMs, deduplicated, and requestUrl
- Pagination utilities: RFC Link header parsing, cursor helpers, offset/limit and page adapters; Paged
- Token refresh: SimpleAuthRefreshConfig and AuthRefreshInterceptor
- Fluent uploads with FormData helpers (upload(), field/fields, files, fileFromPath/Bytes/Stream)
Breaking changes:
- Timeout values in constants now use Duration instead of int milliseconds
- Public API surface expanded; ensure imports use
package:sonic/sonic.dart
Docs:
- README simplified with links to GitHub Wiki, plus quick examples
- Cookbook added with pagination, templates, circuit breaker, and metrics recipes
Tooling:
- Added GitHub Actions workflows for wiki preview and link checking
0.0.3 #
- Documentation Update
0.0.2 #
- Initial version.