dio_curl_interceptor 0.0.1
dio_curl_interceptor: ^0.0.1 copied to clipboard
A new Flutter package for logging curl with dio interceptor.
dio_curl_interceptor #
A Flutter package that provides a Dio interceptor for logging HTTP requests as cURL commands. This makes it easier to debug API calls and share them with others.
Features #
- π Automatically converts Dio HTTP requests to cURL commands
- π Logs cURL commands to the console for easy debugging
- βοΈ Configurable options for logging behavior
- π Support for FormData conversion
- π― Minimal setup required
Getting started #
Add dio_curl_interceptor
to your pubspec.yaml
file:
dependencies:
dio_curl_interceptor: ^0.0.1
Then run:
flutter pub get
Usage #
- First, import the package:
import 'package:dio_curl_interceptor/dio_curl_interceptor.dart';
- Add the interceptor to your Dio instance:
final dio = Dio();
dio.interceptors.add(CurlInterceptor());
Configuration Options #
You can customize the interceptor behavior with these options:
dio.interceptors.add(
CurlInterceptor(
printOnSuccess: true, // Only print cURL commands for successful requests
convertFormData: true, // Convert FormData to JSON in cURL output
),
);
Example Output #
When making a POST request with JSON data:
final response = await dio.post(
'https://api.example.com/data',
data: {'name': 'John', 'age': 30},
);
The interceptor will log something like:
curl -i -X POST -H "Content-Type: application/json; charset=utf-8" -d "{\"name\":\"John\",\"age\":30}" "https://api.example.com/data"
Additional information #
- Repository: GitHub
- Bug Reports: Please file issues on the GitHub repository
- Feature Requests: Feel free to suggest new features through GitHub issues
Contributions are welcome! Please feel free to submit a Pull Request.