curl_logger

A Flutter/Dart package that logs HTTP requests as cURL commands and prints response summaries — supports both Dio and http packages.


✨ Features

  • 🚀 Logs every request as a ready-to-paste cURL command
  • 🌐 Prints response summaries with status emoji
  • 🔒 Automatically obscures sensitive headers (authorization, cookie)
  • đŸ“Ļ Supports truncated body preview for large responses
  • đŸŽ¯ Works with Dio (DioCurlInterceptor) and http (HttpCurlClient)
  • đŸ–Ĩī¸ Pretty-prints JSON bodies for readability

đŸ“Ļ Installation

Add to your pubspec.yaml:

dependencies:
  curl_logger: ^1.0.0

Then run:

flutter pub get

🚀 Usage

With Dio

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

void main() {
  final dio = Dio()
    ..interceptors.add(
      DioCurlInterceptor(
        prettyJson: true,      // pretty print JSON body (default: true)
        previewLength: 2000,   // max response body preview chars (default: 2000)
      ),
    );

  dio.get('https://jsonplaceholder.typicode.com/posts/1');
}

Output:

=============================================================================================
================================🚀🚀 Curl Logger Request 🚀🚀================================
=============================================================================================
curl --location --request GET 'https://jsonplaceholder.typicode.com/posts/1' \
--header 'content-type: application/json' \

=============================================================================================
================================🌐🌐 Curl Logger Response 🌐🌐===============================
=============================================================================================
HTTP ✅ 200
BODY đŸ“Ļ : {"userId":1,"id":1,"title":"...","body":"..."}

With http

import 'package:curl_logger/curl_logger.dart';

void main() async {
  final client = HttpCurlClient(
    prettyJson: true,
    previewLength: 2000,
  );

  await client.get(
    Uri.parse('https://jsonplaceholder.typicode.com/posts/1'),
  );

  client.close();
}

Using buildCurl manually

You can also build a cURL string manually without any HTTP client:

import 'package:curl_logger/curl_logger.dart';

void main() {
  final curl = buildCurl(
    method: 'POST',
    url: Uri.parse('https://api.example.com/login'),
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer my_token', // will be obscured as ***
    },
    body: {'username': 'rohit', 'password': '1234'},
    prettyJson: true,
    obscureHeader: {'authorization', 'cookie'},
  );

  print(curl);
}

Output:

curl --location --request POST 'https://api.example.com/login' \
--header 'Content-Type: application/json' \
--header 'Authorization: ***' \
--data-raw '{
  "username": "rohit",
  "password": "1234"
}'

âš™ī¸ Parameters

DioCurlInterceptor

Parameter Type Default Description
prettyJson bool true Pretty print JSON request body
previewLength int 2000 Max characters to show in response preview

HttpCurlClient

Parameter Type Default Description
prettyJson bool true Pretty print JSON request body
previewLength int 2000 Max characters to show in response preview

buildCurl

Parameter Type Required Description
method String ✅ HTTP method (GET, POST, etc.)
url Uri ✅ Request URL
headers Map<String, String>? ❌ Request headers
body Object? ❌ Request body (Map, List, or String)
prettyJson bool ❌ Pretty print JSON (default: true)
obscureHeader Set<String> ❌ Headers to mask (default: {"authorization", "cookie"})

🔒 Header Obscuring

Sensitive headers like authorization and cookie are automatically replaced with *** in the cURL output. You can customize this:

DioCurlInterceptor(
  // add your own sensitive headers
  // Note: comparison is case-insensitive
)

// Or manually with buildCurl:
buildCurl(
  method: 'GET',
  url: Uri.parse('https://api.example.com'),
  obscureHeader: {'authorization', 'cookie', 'x-api-key'},
);

📊 Response Status Emojis

Status Range Emoji Meaning
1xx â„šī¸ Informational
2xx ✅ Success
3xx 🔀 Redirect
4xx âš ī¸ Client Error
5xx đŸ”Ĩ Server Error

🤝 Contributing

Contributions are welcome! Feel free to open issues or pull requests on GitHub.


📄 License

MIT License — see LICENSE for details.