testing library
Test-only entry point for apix consumers.
Everything needed to exercise network behaviour without I/O: stub an adapter, hand back a scripted body, assert what the client did with it.
These types are deliberately not in package:apix/apix.dart — they have no
business in production autocomplete. Import them only from test/:
import 'package:apix/apix.dart';
import 'package:apix/testing.dart';
class FakeAdapter implements HttpClientAdapter {
@override
Future<ResponseBody> fetch(
RequestOptions options,
Stream<List<int>>? requestStream,
Future<dynamic>? cancelFuture,
) async {
return ResponseBody.fromString(
'{"code":"RATE_LIMITED","message":"Slow down"}',
429,
headers: {
Headers.contentTypeHeader: ['application/json'],
'retry-after': ['30'],
},
);
}
@override
void close({bool force = false}) {}
}
final client = ApiClientFactory.create(
baseUrl: 'https://api.test',
httpClientAdapter: FakeAdapter(),
);
Without this entry point every consumer's network test had to
import 'package:dio/dio.dart' directly, which made apix's declared dio
version range a constraint on their test suite too — the one place a range
mismatch is most likely to surface first.
Classes
- BaseOptions
-
A set of base settings for each
Dio(). BaseOptions and Options will be merged into one RequestOptions before sending the requests. See Options.compose. - Dio
- Dio enables you to make HTTP requests easily.
- Headers
- The headers class for requests and responses.
- HttpClientAdapter
-
HttpAdapteris a bridge between Dio and HttpClient. - RequestOptions
- The internal request option class that is the eventual result after BaseOptions and Options are composed.
- ResponseBody
- The response wrapper class for adapters.
Enums
- ResponseType
- Indicates which transformation should be applied to the response data.