LogCurlRequest is a Flutter package designed to streamline the creation of cURL
commands from your HTTP request details. This package provides developers with a simple and effective way to log HTTP requests as cURL
commands, facilitating debugging and sharing of API calls.
- Introduction
- Features
- Installation
- Usage
- Example
- Configuration
- Dependencies
- Troubleshooting
- Contributors
- License
- Generate
cURL
commands for HTTP requests. - Supports adding HTTP headers, body data (JSON or plain text), and query parameters.
- Optionally logs the generated
cURL
command using Flutter'sdebugPrint
. - Easy to integrate with existing Flutter projects.
To use this package, add the following to your pubspec.yaml
file:
dependencies:
log_curl_request: ^0.0.5
Then, run:
flutter pub get
Import the package into your Dart file:
import 'package:log_curl_request/log_curl_request.dart';
Generate a cURL
command:
String curlCommand = LogCurlRequest.create(
"POST",
"https://api.example.com/resource",
parameters: {"key": "value"},
data: {"field": "value"},
headers: {"Authorization": "Bearer YOUR_TOKEN"},
showDebugPrint: true,
);
This will generate and optionally log a cURL
command like:
curl -X POST -H "Authorization: Bearer YOUR_TOKEN" --data '{"field":"value"}' "https://api.example.com/resource?key=value"
Here’s an example of using the package to log a cURL
command:
void main() {
String curlCommand = LogCurlRequest.create(
"GET",
"https://api.example.com/users",
parameters: {"page": "1", "limit": "10"},
headers: {"Content-Type": "application/json"},
showDebugPrint: true,
);
print(curlCommand);
}
Expected Output (logged via debugPrint
):
cURL command:
curl -X GET -H "Content-Type: application/json" "https://api.example.com/users?page=1&limit=10"
- method: The HTTP method (e.g.,
GET
,POST
). - path: The API endpoint.
- parameters: (Optional) Query parameters as a
Map<String, dynamic>
. - data: (Optional) The request body (supports
Map
orString
). - headers: (Optional) HTTP headers as a
Map<String, dynamic>
. - showDebugPrint: (Optional) A boolean to enable logging of the generated
cURL
command.
dart:convert
package:flutter/foundation.dart
Ensure you have Flutter SDK installed and set up in your development environment.
-
Issue:
cURL
command not logging.- Solution: Ensure
showDebugPrint
is set totrue
.
- Solution: Ensure
-
Issue: Malformed
cURL
command.- Solution: Verify the data format and parameter types passed to the method.
This package was authored by [Your Name/Team]. Contributions are welcome. Please submit issues and pull requests on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.