testing library

Test doubles for consumers of this package.

Import this in your own tests to get a working FakeApiServices without writing mocktail boilerplate against the ApiServices interface:

import 'package:baaba_api_handler/testing.dart';

Nothing here is imported by the package's production code, so it adds no weight to your app.

Classes

ApiConfig
Everything ApiServices needs, in one object.
ApiLogOptions
Controls what the console logger prints for each request.
ApiObserver
A single place to watch every request the package makes — for crash reporting, analytics, or a debug overlay.
ApiServices
A typed HTTP client wrapping Dio. All methods return Either<Failure, Response> — use .fold(onLeft, onRight) to handle errors and successes without exceptions.
AuthConfig
Token-based authentication settings for ApiServices.
BaabaApiEndpoint
Generates typed endpoints from a .env file of KEY=path lines.
BaabaApiEnvironment
Generates typed configuration values from a .env file.
BaabaApiField
Names the .env key a field reads, instead of its UPPER_SNAKE name.
Base64LogTrimmer
Collapses base64 blobs out of the logger's output.
CancelToken
Controls cancellation of Dio's requests.
Either<L, R>
Represents a value of one of two possible types, Left or Right.
ErrorInterceptorHandler
The handler for interceptors to handle error occurred during the request.
FakeApiServices
An in-memory ApiServices for tests, so you can exercise a repository or controller without mocking Dio or standing up a server.
FormData
A class to create readable "multipart/form-data" streams. It can be used to submit forms and file uploads to http server.
HttpClientAdapter
HttpAdapter is a bridge between Dio and HttpClient.
Interceptor
Interceptor helps to deal with RequestOptions, Response, and DioException during the lifecycle of a request before it reaches users.
InterceptorsWrapper
A helper class to create interceptors in ease.
Left<L, R>
MultipartFile
An upload content that is a part of MultipartRequest. This doesn't need to correspond to a physical file.
PinningConfig
Certificate pinning by CA: each host is trusted only if its certificate chains to one of the roots listed for it.
ProxyConfig
Sends requests for selected hosts through an HTTP proxy, and everything else direct.
QueuedInterceptor
Interceptor in queue.
RecordedCall
One call made against a FakeApiServices, captured for assertions.
RequestInterceptorHandler
The handler for interceptors to handle before the request has been sent.
RequestOptions
The internal request option class that is the eventual result after BaseOptions and Options are composed.
Response<T>
The Response class contains the payload (could be transformed) that respond from the request, and other information of the response.
ResponseInterceptorHandler
The handler for interceptors to handle after respond.
RetryPolicy
Controls how transient failures are retried by NetworkRetryInterceptor.
UploadFile
One file in a multipart upload.

Enums

DioExceptionType
The exception enumeration indicates what type of exception has happened during requests.
ErrorSource
HttpMethod
RefreshOutcome
What a token refresh came to, for AuthConfig.refreshSession.
ResponseCode
ResponseType
Indicates which transformation should be applied to the response data.
UnlistedHostPolicy
What a pinned client does with a host PinningConfig does not list.

Extension Types

ApiEndpoint
An endpoint path, optionally with {} placeholders filled in order.

Extensions

ApiResultOrThrow on Future<Either<Failure, T>>
orThrow() on a request's result, for chaining calls.
EitherOrThrow on Either<Failure, T>
orThrow() on a result already awaited.
HttpMethodExtension on HttpMethod

Functions

guardApi<T>(Future<T> body(), {void onUnexpected(Object error, StackTrace stackTrace)?, String client = ApiServices.defaultClient}) → Future<Either<Failure, T>>
Runs body and returns its result as an Either, so a flow written with orThrow() hands its caller the same type a single request does.
jwtExpired(String token, {Duration skew = const Duration(seconds: 30), DateTime? now}) → bool
Whether the JWT token has expired, or will within skew.
jwtExpiryCheck(Future<String?> getToken(), {Duration skew = const Duration(seconds: 30)}) → Future<bool> Function()
jwtExpired, shaped for AuthConfig.isTokenExpired: reads the token with getToken — usually the same function given to AuthConfig.getToken — and checks it.
listParser<T>(T fromJson(Map<String, dynamic> json), {String? key}) → List<T> Function(dynamic data)
Turns a single-object parser into one that reads a JSON array, for the common list endpoint.

Exceptions / Errors

ApiException
A Failure, thrown.
DioException
DioException describes the exception info when a request failed.
Failure
Represents a failure from ApiServices, carrying the error type, HTTP/internal code, and a human-readable message.