packages/api_kit/api_kit library

Classes

ApiCache
In-memory implementation of CacheStore with TTL-based expiry and optional ETag storage for revalidation.
ApiInterceptor
Interceptor for logging and token handling.
ApiKit
A reusable API client for HTTP requests.
ApiLogger
Injectable, instance-based logger for the API kit.
CacheEntry
A cached entry holding a value, its expiry, and an optional ETag for revalidation.
CacheStore
Abstraction over a cache storage backend.
ConnectivityChecker
Strategy for checking network connectivity before a request is made.
CursorPaginationStrategy
Cursor-based pagination strategy.
FlexibleInterceptor
A flexible interceptor that allows custom request/response handling
NoOpConnectivityChecker
Default connectivity checker that always reports a connection.
OffsetPaginationStrategy
Offset-based pagination strategy driven by a PaginationConfig.
PaginatedResponse<T>
A parsed paginated response.
PaginationConfig
Configuration for offset-based pagination with configurable field keys.
PaginationStrategy
Strategy that parses a paginated API response into a PaginatedResponse.
RequestDeduplicator
De-duplicates concurrent identical in-flight requests.
TokenRefreshInterceptor
Interceptor that performs automatic token refresh-and-retry on 401.

Enums

LogLevel
Log levels for the API logger.

Constants

kRefreshedExtraKey → const String
Key used in RequestOptions.extra to mark a request as already refreshed, preventing infinite refresh-and-retry loops.

Functions

mapDioError(dynamic error) Exception
Maps a DioException to a typed ApiBaseException, preserving the server response body so callers can reach field-level validation details.
parseResponse<T>(Response response, T parser(Map<String, dynamic> json)) → T
Parses a successful Dio response using a custom JSON parser.

Typedefs

TokenRefresher = Future<String?> Function(DioException error, RequestOptions options)
Strategy that refreshes an expired auth token after a 401 response.

Exceptions / Errors

ApiBaseException
Base class for all API network exceptions.
ApiException
Generic API exception used when no more specific exception type applies.
BadGatewayException
Exception thrown when a gateway receives an invalid upstream response.
BadRequestException
Exception thrown when a request is malformed or invalid.
ConflictException
Exception thrown when a request conflicts with the current resource state.
ForbiddenException
Exception thrown when the caller is not permitted to access a resource.
GatewayTimeoutException
Exception thrown when an upstream server times out.
InternalServerErrorException
Exception thrown when the server reports an internal error.
NetworkException
Exception thrown when a request fails because of network connectivity.
NoInternetException
Exception thrown when no internet connection is available.
NotFoundException
Exception thrown when the requested resource cannot be found.
ServerException
Exception thrown when the server returns an unexpected error response.
ServiceUnavailableException
Exception thrown when the service is temporarily unavailable.
TimeoutException
Exception thrown when a request exceeds its configured timeout.
TooManyRequestsException
Exception thrown when the server rate-limits the request.
UnauthorizedException
Exception thrown when a request lacks valid authentication credentials.
UnprocessableEntityException
Exception thrown when a request is valid but cannot be processed.