dio_curl_interceptor 4.1.0-beta.1 copy "dio_curl_interceptor: ^4.1.0-beta.1" to clipboard
dio_curl_interceptor: ^4.1.0-beta.1 copied to clipboard

A Dio interceptor that converts HTTP requests to cURL commands, with pluggable sinks, an in-app viewer, local caching, and webhook integration.

example/example.dart

import 'package:dio/dio.dart';
import 'package:dio_curl_interceptor/dio_curl_interceptor.dart';
import 'package:flutter/widgets.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await CachedCurlService.init();

  final dio = Dio();

  // Example 1: Minimal — relays through the NullSink (no extra output).
  dio.interceptors.add(
    DioCurlInterceptor(config: CurlConfig(sinks: [NullSink()])),
  );

  // Example 2: Configure logging + bodies with explicit sinks.
  dio.interceptors.add(
    DioCurlInterceptor(
      config: CurlConfig(
        sinks: [PrinterSink(printer: (text) => debugPrint('[Curl] $text'))],
        onResponse: const ResponseDetails(
          visible: true,
          requestBody: true,
          responseBody: true,
        ),
        onError: const ErrorDetails(
          visible: true,
          requestBody: true,
          responseBody: true,
        ),
      ),
    ),
  );

  // Example 3: Discord + Telegram webhooks + Hive cache + console printer.
  dio.interceptors.add(
    DioCurlInterceptor(
      config: CurlConfig(
        sinks: [
          DiscordSink(
            name: 'discord-alerts',
            webhookUrl: 'https://discord.com/api/webhooks/your-webhook-url',
          ),
          TelegramSink(
            name: 'telegram-alerts',
            botToken: 'YOUR_BOT_TOKEN',
            chatId: '-1003019608685',
          ),
          HiveSink(),
          PrinterSink(printer: print),
        ],
        relayOptions: const RelayOptions(circuitBreaker: true),
      ),
    ),
  );

  // Example 4: Manual, non-HTTP message via sendMessage.
  final interceptor = DioCurlInterceptor(
    config: CurlConfig(sinks: [NullSink()]),
  );
  await interceptor.sendMessage('App started');

  // Example 5: Custom relay tuning — turn off dedupe while keeping the breaker.
  dio.interceptors.add(
    DioCurlInterceptor(
      config: CurlConfig(
        relayOptions: const RelayOptions(
          circuitBreaker: true,
          dedupeTtl: Duration.zero,
        ),
        sinks: [PrinterSink(printer: print)],
      ),
    ),
  );
}
4
likes
160
points
965
downloads

Documentation

API reference

Publisher

verified publishervenhdev.me

Weekly Downloads

A Dio interceptor that converts HTTP requests to cURL commands, with pluggable sinks, an in-app viewer, local caching, and webhook integration.

Repository (GitHub)
View/report issues

Topics

#curl #dio #logging #console #monitor

License

MIT (license)

Dependencies

colored_logger, crypto, dio, flutter, hive_ce, hive_ce_flutter, logging, path_provider, share_plus, shared_preferences, type_caster

More

Packages that depend on dio_curl_interceptor