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
cURLcommand - đ 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.