curl_logger 1.0.1 copy "curl_logger: ^1.0.1" to clipboard
curl_logger: ^1.0.1 copied to clipboard

A Flutter/Dart HTTP logger that prints requests as cURL commands with response summaries. Supports both Dio and http packages.

example/curl_logger_example.dart

import 'dart:convert';
import 'package:curl_logger/curl_logger.dart';
import 'package:dio/dio.dart';

void main() async {
  // ─── Example 1: Dio with DioCurlInterceptor ───────────────────────────────
  final dio = Dio()
    ..interceptors.add(
      DioCurlInterceptor(
        prettyJson: true,
        previewLength: 2000,
      ),
    );

  // Simple GET request
  await dio.get('https://jsonplaceholder.typicode.com/posts/1');

  // POST request with JSON body
  await dio.post(
    'https://jsonplaceholder.typicode.com/posts',
    options: Options(headers: {'Content-Type': 'application/json'}),
    data: {
      'title': 'Hello curl_logger',
      'body': 'This request was logged as a cURL command!',
      'userId': 1,
    },
  );

  // ─── Example 2: http with HttpCurlClient ──────────────────────────────────
  final client = HttpCurlClient(
    prettyJson: true,
    previewLength: 2000,
  );

  await client.post(
    Uri.parse('https://jsonplaceholder.typicode.com/posts'),
    headers: {'Content-Type': 'application/json'},
    body: jsonEncode({
      'title': 'Hello from http client',
      'body': 'Logged via HttpCurlClient',
      'userId': 1,
    }),
  );

  client.close();

  // ─── Example 3: buildCurl manually ────────────────────────────────────────
  final curl = buildCurl(
    method: 'POST',
    url: Uri.parse('https://api.example.com/login'),
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer my_secret_token', // auto-obscured as ***
    },
    body: {'username': 'john', 'password': 'secret'},
    prettyJson: true,
  );

  print('Manual cURL:\n$curl');
}
2
likes
160
points
130
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter/Dart HTTP logger that prints requests as cURL commands with response summaries. Supports both Dio and http packages.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dio, http

More

Packages that depend on curl_logger