Skip to main content

peek_chopper 2.1.1 copy "peek_chopper: ^2.1.1" to clipboard
peek_chopper: ^2.1.1 copied to clipboard

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

example/peek_chopper_example.dart

// Everything Peek needs to show the calls Chopper makes: one interceptor in
// the client's chain. 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:chopper/chopper.dart';
import 'package:peek/core.dart';
import 'package:peek_chopper/peek_chopper.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 base = Uri.parse('https://httpbin.org');
  final client = ChopperClient(
    baseUrl: base,
    interceptors: [PeekChopperInterceptor(peek)],
  );

  await client.send<dynamic, dynamic>(
    Request(
      'GET',
      Uri.parse('/bearer'),
      base,
      headers: const {'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',
  );

  client.dispose();
  peek.dispose();
}
1
likes
160
points
520
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

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

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#chopper #debugging #http #logging #network

License

MIT (license)

Dependencies

chopper, http, peek

More

Packages that depend on peek_chopper