log_curl_request 0.0.2
log_curl_request: ^0.0.2 copied to clipboard
A Flutter package to log HTTP requests in cURL format for debugging and testing purposes.
LogCurlRequest - Flutter Package #
Introduction #
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.
Table of Contents #
- Introduction
- Features
- Installation
- Usage
- Example
- Configuration
- Dependencies
- Troubleshooting
- Contributors
- License
Features #
- Generate
cURLcommands for HTTP requests. - Supports adding HTTP headers, body data (JSON or plain text), and query parameters.
- Optionally logs the generated
cURLcommand using Flutter'sdebugPrint. - Easy to integrate with existing Flutter projects.
Installation #
To use this package, add the following to your pubspec.yaml file:
dependencies:
log_curl_request:
path: <path_to_your_package> # Replace with the package path
Then, run:
flutter pub get
Usage #
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"
Example #
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"
Configuration #
Parameters #
- 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
MaporString). - headers: (Optional) HTTP headers as a
Map<String, dynamic>. - showDebugPrint: (Optional) A boolean to enable logging of the generated
cURLcommand.
Dependencies #
dart:convertpackage:flutter/foundation.dart
Ensure you have Flutter SDK installed and set up in your development environment.
Troubleshooting #
-
Issue:
cURLcommand not logging.- Solution: Ensure
showDebugPrintis set totrue.
- Solution: Ensure
-
Issue: Malformed
cURLcommand.- Solution: Verify the data format and parameter types passed to the method.
Contributors #
This package was authored by [Your Name/Team]. Contributions are welcome. Please submit issues and pull requests on the GitHub repository.
License #
This project is licensed under the MIT License. See the LICENSE file for details.