Skip to main content

peek_dio 2.0.0 copy "peek_dio: ^2.0.0" to clipboard
peek_dio: ^2.0.0 copied to clipboard

Reports the calls Dio makes to Peek, so they can be read in the app.

example/peek_dio_example.dart

// Everything Peek needs to show the calls Dio makes: one interceptor on
// the client. This is a Dart script so it can run anywhere; in an app the
// screen opens with `showPeek(context, peek: peek)`, and the full app is
// under `packages/peek/example`.

import 'package:dio/dio.dart';
import 'package:peek/core.dart';
import 'package:peek_dio/peek_dio.dart';

/// Records one call and reads it back from the store.
Future<void> main() async {
  // Masking is opt-in; the default policy covers the usual secret names.
  final peek = Peek(
    options: const PeekOptions(redaction: PeekRedactionPolicy()),
  );
  final dio = Dio()..interceptors.add(PeekDioInterceptor(peek));

  await dio.get<dynamic>(
    'https://httpbin.org/bearer',
    options: Options(headers: {'Authorization': 'Bearer not-for-the-log'}),
  );

  final entry = peek.store.entries.single;
  assert(entry.statusCode == 200, 'the call was recorded as it went');
  assert(
    entry.request.headers['authorization'] == '*****',
    'the policy masked the token before it was stored',
  );

  peek.dispose();
}
1
likes
0
points
548
downloads

Publisher

unverified uploader

Weekly Downloads

Reports the calls Dio makes to Peek, so they can be read in the app.

Homepage
Repository (GitHub)
View/report issues

Topics

#debugging #dio #http #logging #network

License

unknown (license)

Dependencies

dio, peek

More

Packages that depend on peek_dio