network_caller_dio library
Classes
- ApiKeyAuthStrategy
- Adds an API key to requests — either as a header or a query parameter.
- AuthStrategy
- Determines how authentication headers are built for each request.
- BasicAuthStrategy
-
Adds
Authorization: Basic <base64(username:password)>to requests. - BearerAuthStrategy
-
Reads the access token from TokenManager and adds
Authorization: Bearer <token>. - CancelToken
- Opaque cancel token for aborting in-flight requests.
- ConsoleNetworkLogger
- Default logger that prints to the Dart developer console.
- CustomAuthStrategy
- Lets the consumer provide a custom function that builds auth headers.
- DioCancelToken
-
CancelToken implementation wrapping Dio's native
dio.CancelToken. - DioNetworkCaller
-
Full NetworkInterface implementation using the
diopackage. - ErrorResponse
- Structured error details returned inside NetworkResponse on failure.
- InMemoryTokenStorage
- In-memory token storage for testing and non-Flutter contexts.
- LoggingInterceptor
- Dio interceptor that forwards request/response/error events to a NetworkLogger instance.
- MiddlewareRequestContext
- Mutable request options that middlewares can modify before the request is sent.
- NetworkConfig
- Central configuration for the network caller.
- NetworkInterface
- Abstract contract that both HTTP and Dio callers implement.
- NetworkLogger
- Abstract interface for logging network requests and responses.
- NetworkMiddleware
- Middleware hook for the HTTP implementation.
- NetworkMultipartFile
- Platform-agnostic file representation for multipart uploads.
-
NetworkResponse<
T> - Generic response wrapper for every network call.
- ResponseParser
- Shared response parsing logic used by both HTTP and Dio implementations.
- RetryPolicy
- Configures automatic retry behavior for failed requests.
- SecureTokenStorage
-
Concrete TokenStorage implementation backed by
FlutterSecureStorage. - TokenManager
- Instance-based token manager that wraps a TokenStorage implementation.
- TokenStorage
- Abstract interface for persisting auth tokens.
Enums
- ApiKeyLocation
- Where the API key should be placed.
- RequestMethod
- HTTP request methods supported by the network caller.
- ResponseType
- Controls how the HTTP response body is decoded.
Typedefs
- ErrorParser = ErrorResponse Function(int statusCode, dynamic body)
- Custom error parser for APIs with non-standard error structures.
- MessageExtractor = String? Function(dynamic body)
- Extracts the user-facing message from the response body.
- ResponseUnwrapper = dynamic Function(dynamic body)
- Extracts a specific field from the response body before passing to the parser.
-
TokenExtractor
= ({String? accessToken, String? refreshToken}) Function(Map<
String, dynamic> body) - Callback to extract tokens from a refresh endpoint response body.
Exceptions / Errors
- ClientException
- Server returned a 4xx status code (excluding 401 and 429).
- NetworkException
- Base exception for all network-related errors.
- NetworkTimeoutException
- Request timed out (connect, send, or receive).
- NoConnectionException
- Device has no internet connection (SocketException, DNS failure, etc.).
- ParseException
-
JSON decoding failed, or the user-provided
parsercallback threw. - RateLimitException
- Server returned 429 Too Many Requests.
- RequestCancelledException
- The request was explicitly cancelled via a CancelToken.
- ServerException
- Server returned a 5xx status code.
- SslException
- SSL/TLS certificate validation failed (bad certificate, expired, etc.).
- Server returned 401 and token refresh failed or was not possible.