waste_lens_dio 0.1.0 copy "waste_lens_dio: ^0.1.0" to clipboard
waste_lens_dio: ^0.1.0 copied to clipboard

Dio add-on for waste_lens: detect redundant API calls, coalesce in-flight duplicate requests, and report wasted bytes via the waste_lens overlay.

example/example.dart

import 'package:dio/dio.dart';
import 'package:waste_lens/waste_lens.dart';
import 'package:waste_lens_dio/waste_lens_dio.dart';

/// Add the interceptor to your Dio client. Pass the running `waste_lens` bus to
/// surface findings in the overlay, and read [RedundantCallInterceptor.report]
/// for a summary.
Future<void> main() async {
  final interceptor = RedundantCallInterceptor(
    bus: WasteLens.current?.bus,
    coalesce: true, // collapse in-flight idempotent duplicates into one call
    redundancyWindow: const Duration(seconds: 2),
  );

  final dio = Dio(BaseOptions(baseUrl: 'https://api.example.com'))
    ..interceptors.add(interceptor);

  // Fire the same request a few times; duplicates are coalesced/flagged.
  await Future.wait([
    for (var i = 0; i < 5; i++) dio.get<dynamic>('/users'),
  ]);

  final report = interceptor.report;
  // ignore: avoid_print
  print('${report.redundantCalls} redundant (${report.wastedPercent}% wasted)');
}
0
likes
160
points
173
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Dio add-on for waste_lens: detect redundant API calls, coalesce in-flight duplicate requests, and report wasted bytes via the waste_lens overlay.

Repository (GitHub)
View/report issues
Contributing

Topics

#performance #profiling #debugging #dio

License

MIT (license)

Dependencies

crypto, dio, flutter, meta, waste_lens

More

Packages that depend on waste_lens_dio