sonic library

Sonic is a HTTP client made on top of Dio to have better support for types and provide a fluent interface for the calls.

Classes

AuthRefreshInterceptor
A helper interceptor to handle 401 responses by refreshing tokens and retrying.
BaseConfiguration
Global defaults for the Sonic client instance.
CachePolicy
Default caching behavior for GET requests.
CancelToken
Controls cancellation of Dio's requests.
CircuitBreakerConfig
Configuration for a simple circuit breaker.
CompositeCacheStore
A composite cache that prefers the memory store and writes to both memory and file stores. File hits are promoted into memory.
DecodeError
DecodeResult<T>
DefaultAuthRefreshHandler
Default implementation of IAuthRefreshHandler using callback functions.
FileCacheStore
A simple file-backed cache store. Not optimized for large-scale use, but adequate as a persistent cache example.
FormData
A class to create readable "multipart/form-data" streams. It can be used to submit forms and file uploads to http server.
IAuthRefreshHandler
Interface for handling authentication token refresh logic.
MediaType
A class representing an HTTP media type, as used in Accept and Content-Type headers.
MultipartFile
An upload content that is a part of MultipartRequest. This doesn't need to correspond to a physical file.
Paged<T>
A page of items with optional next/prev references.
RateLimitConfig
Simple token-bucket rate limit configuration. permitsPerSecond controls refill rate; burst is the bucket capacity.
RequestOptions
The internal request option class that is the eventual result after BaseOptions and Options are composed.
RetryOptions
Configuration for automatic retries with backoff and jitter.
SimpleAuthRefreshConfig
Simple configuration for auth refresh using callback functions.
Sonic
A high-level HTTP client with a fluent builder API on top of Dio.
SonicPageRef<T>
A reference to another page with a URL and item list decoder.
SonicRequestBuilder<T>
The Request Builder.
SonicResponse<T>

Enums

CircuitState
States for a circuit breaker.
DioExceptionType
The exception enumeration indicates what type of exception has happened during requests.
HttpMethod
RequestPriority
ResponseType
Indicates which transformation should be applied to the response data.

Functions

addOrReplaceQueryParam(String url, String key, String value) → String
Add or replace a query parameter in the URL.
advanceOffsetLimit({required String url, required int pageSize, String offsetKey = 'offset', String limitKey = 'limit', bool next = true}) → String
Advance an offset/limit style URL forward/backward by one page.
advancePageNumber({required String url, String pageKey = 'page', bool next = true}) → String
Advance a page-number style URL forward/backward by one.
makePaged<T>({required dynamic body, required Map<String, List<String>>? headers, required String? requestUrl, required T itemDecoder(dynamic json), String? itemsPath, String? nextCursorPath, String? prevCursorPath, String cursorParam = 'cursor'}) → Paged<T>
Build a Paged
parseLinkHeader(Headers headers) → Map<String, String>
Parse HTTP Link header for rel="next"/"prev" URLs.
parseLinkHeaderFromMap(Map<String, List<String>> headers) → Map<String, String>
Variant of parseLinkHeader for a simple headers map.
pluckValue(dynamic data, String path) → dynamic
Lightweight JSON plucker: supports dot paths and [index] for lists.
safeDecoder<T>(T decoder(dynamic json)) → DecodeResult<T> Function(dynamic json)

Typedefs

DioMediaType = MediaType
The type (alias) for specifying the content-type of the MultipartFile.

Exceptions / Errors

DioException
DioException describes the exception info when a request failed.