Skip to main content

mockbeam_record 1.0.0 copy "mockbeam_record: ^1.0.0" to clipboard
mockbeam_record: ^1.0.0 copied to clipboard

A Dart CLI proxy that captures real HTTP API responses and writes them as dio_mock_interceptor-compatible YAML.

example/example.dart

// Programmatic usage of MockBeam Record.
//
// For the typical use case the CLI is simpler:
//   mockbeam_record record --target https://api.example.com
//
// Use the library API when you need to embed the proxy in a test harness,
// a custom tool, or a CI script that records and saves in one step.

import 'dart:io';

import 'package:mockbeam_record/mockbeam_record.dart';

Future<void> main() async {
  final target = Uri.parse('https://jsonplaceholder.typicode.com');

  final server = ProxyServer(
    targetBase: target,
    port: 8080,
  );

  await server.start();
  print('Proxy running on http://localhost:8080');
  print('Press Ctrl+C to stop and save.');

  // Keep running until Ctrl+C.
  await ProcessSignal.sigint.watch().first;

  final count = await server.stop();
  print('\nStopping... $count route(s) captured.');

  final serializer = RouteSerializer();
  final yaml = serializer.toYaml(
    server.routeStore.routes,
    target: target,
  );
  await serializer.writeTo('mocks/recorded.yaml', yaml);
  print('Wrote mocks/recorded.yaml');
}
4
likes
160
points
13
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Dart CLI proxy that captures real HTTP API responses and writes them as dio_mock_interceptor-compatible YAML.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

args, yaml, yaml_writer

More

Packages that depend on mockbeam_record