ispectify_dio 5.0.0-dev32 copy "ispectify_dio: ^5.0.0-dev32" to clipboard
ispectify_dio: ^5.0.0-dev32 copied to clipboard

Dio HTTP client integration for ISpect toolkit

ispectify_dio is a Dio interceptor for the ISpect toolkit. It captures every request/response, pairs them into correlated transactions, and redacts sensitive data before logging.

  • Request / response / error capture with headers, body, status, and duration.
  • Per-call redaction of auth headers, tokens, PII, and credit-card data (on by default).
  • Builder and factory presets for development, staging, and production setups.
  • Works with any Dio instance — attach the interceptor and you're done.

Install #

dependencies:
  dio: ^5.0.0
  ispectify: ^5.0.0-dev32
  ispectify_dio: ^5.0.0-dev32

Quick start #

import 'package:dio/dio.dart';
import 'package:ispect/ispect.dart';
import 'package:ispectify_dio/ispectify_dio.dart';

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

ISpect.run(
  () => runApp(const MyApp()),
  logger: logger,
  onInit: () {
    dio.interceptors.add(
      ISpectDioInterceptor(
        logger: logger,
        settings: const ISpectDioInterceptorSettings(
          printRequestHeaders: true,
          printResponseHeaders: true,
          printRequestData: true,
          printResponseData: true,
        ),
      ),
    );
  },
);

Settings #

ISpectDioInterceptorSettings controls which slices of each call are captured and whether they are redacted before logging. enableRedaction defaults to true on every constructor.

const settings = ISpectDioInterceptorSettings(
  printRequestHeaders: true,
  printRequestData: true,
  printResponseHeaders: false,
  printResponseData: true,
  enableRedaction: true,
);

Preset factories #

// Verbose — full payloads, no redaction. Only for local dev.
final dev = ISpectDioInterceptorSettingsBuilder.development().build();

// Redacted — production-safe defaults, body capture off.
final prod = ISpectDioInterceptorSettingsBuilder.production().build();

// Middle ground — useful for staging environments.
final staging = ISpectDioInterceptorSettingsBuilder.staging().build();

Builder #

final settings = ISpectDioInterceptorSettingsBuilder()
    .withRequestHeaders()
    .withResponseHeaders()
    .withoutRedaction() // not recommended — see "Data redaction" below.
    .build();

Data redaction #

Sensitive data is automatically masked before it reaches logs or observers. Redaction is enabled by default — built-in rules cover auth headers, tokens, passwords, API keys, cookies, PII (SSN, passport, driver's license), financial data (credit cards, IBAN), phone numbers, and more.

Custom keys and patterns #

import 'package:ispectify/ispectify.dart';

final redactor = RedactionService(
  sensitiveKeys: {
    ...defaultSensitiveKeys,
    'x-custom-secret',
    'internal_token',
  },
  sensitiveKeyPatterns: [
    RegExp(r'my_app_secret_\w+', caseSensitive: false),
  ],
  // Keys where the value is replaced entirely (not edge-masked).
  fullyMaskedKeys: {'filename'},
  placeholder: '***',
  visibleEdgeLength: 3,
  redactBinary: true,
  redactBase64: true,
);

Ignoring defaults #

final redactor = RedactionService(
  // e.g., ?mobile=true is a platform flag, not a phone number.
  ignoredKeys: {'mobile', 'platform_token'},
  ignoredValues: {'<test-token>', 'public-api-key'},
);

Disabling #

Each interceptor accepts enableRedaction: false on its settings object. See the per-package README for the exact settings type.

Disable redaction for a single interceptor instance (not recommended — use only for deterministic replay in test environments):

ISpectDioInterceptor(
  logger: logger,
  settings: const ISpectDioInterceptorSettings(enableRedaction: false),
);

Supply a custom RedactionService:

ISpectDioInterceptor(
  logger: logger,
  redactor: RedactionService(
    sensitiveKeys: {...defaultSensitiveKeys, 'x-tenant-token'},
  ),
);

The ISpect toolkit #

ISpect is a modular monorepo. Install only what your project needs — each package works independently.

Package What it does
ispect Flutter UI — debug panel, log viewer, navigation observer, inspector integration
ispect_layout Visual layout inspector — sizes, constraints, decorations, compare mode, color picker
ispectify Pure-Dart logging core — typed log entries, filtering, tracing, observers
ispectify_dio Dio HTTP interceptor with automatic redaction
ispectify_http http package interceptor with automatic redaction
ispectify_ws WebSocket traffic capture with automatic redaction
ispectify_db Database operation tracing (SQL, ORM, KV stores)
ispectify_bloc BLoC event / state / transition observer

Contributing #

Contributions are welcome. See CONTRIBUTING.md for guidelines, and open issues or pull requests at the ISpect repository.

License #

MIT — see LICENSE.


0
likes
0
points
4.86k
downloads

Publisher

verified publishershodev.live

Weekly Downloads

Dio HTTP client integration for ISpect toolkit

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

ansicolor, dio, ispectify

More

Packages that depend on ispectify_dio