package:http
devpul_http reports package:http calls.
dependencies: devpul: ^1.1.1 devpul_http: ^1.1.0Or run devpul add http, which runs pub add for both.
import 'package:devpul_http/devpul_http.dart';
final client = DevpulClient();
Future<String> items() => client.read(Uri.parse('https://example.com/items'));DevpulClient wraps another Client, Client() by default, so it works with IOClient, BrowserClient, cupertino_http, cronet_http and anything else that implements Client:
final client = DevpulClient(RetryClient(Client()));Pass it wherever your code or a package takes a Client.
Every client in the app
Section titled “Every client in the app”Packages that create their own Client() bypass a client you pass around. runWithClient from package:http makes Client() return a DevpulClient for everything that runs inside it, so their calls show and mocks apply to them:
void main() => http.runWithClient(() { WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp());}, DevpulClient.new);Initialize the binding inside it, or Flutter warns of a zone mismatch.
What it records:
- method, URL, query params, headers and body; form bodies as fields,
MultipartRequestas fields and file names - status, reason, headers, body and duration of the response, and the final URL when the platform reports redirects
- exceptions such as
ClientExceptionas errors, rethrown unchanged
Response bodies are read in full before your code gets them, which suits API calls. text/event-stream responses pass through untouched and show as <stream>, as do StreamedRequest bodies. Images show as previews while their base64 fits maxValueLength; other binary bodies show their size.
Mock rules and breakpoints apply to its calls. Calls made with a Request, as get, post and the other helpers make them, can be replayed; a replay goes out through the wrapped client.