{"id":23860388,"url":"https://github.com/moein-dev/log_curl_request","last_synced_at":"2025-10-12T23:11:13.973Z","repository":{"id":270460603,"uuid":"910447260","full_name":"Moein-dev/log_curl_request","owner":"Moein-dev","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-26T10:07:40.000Z","size":278,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T11:19:20.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Moein-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-31T09:49:13.000Z","updated_at":"2025-01-26T10:07:44.000Z","dependencies_parsed_at":"2024-12-31T11:07:16.669Z","dependency_job_id":"07add78f-333a-4c14-9bf1-bb1f1aa88b5d","html_url":"https://github.com/Moein-dev/log_curl_request","commit_stats":null,"previous_names":["moein-dev/log_curl_request"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moein-dev%2Flog_curl_request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moein-dev%2Flog_curl_request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moein-dev%2Flog_curl_request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moein-dev%2Flog_curl_request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Moein-dev","download_url":"https://codeload.github.com/Moein-dev/log_curl_request/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240170054,"owners_count":19759141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-03T04:55:20.152Z","updated_at":"2025-10-12T23:11:13.950Z","avatar_url":"https://github.com/Moein-dev.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LogCurlRequest - Flutter Package\n\n## Introduction\n\n**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.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Example](#example)\n- [Advanced Features](#advanced-features)\n  - [File Uploads](#file-uploads)\n  - [Cookies](#cookies)\n  - [cURL Options](#curl-options)\n  - [Masking Sensitive Information](#masking-sensitive-information)\n  - [Formatted Output](#formatted-output)\n  - [HTTP Client Integration](#http-client-integration)\n- [Global Configuration](#global-configuration)\n  - [Custom Logging](#custom-logging)\n  - [Default Settings](#default-settings)\n- [Error Handling](#error-handling)\n- [Configuration Parameters](#configuration-parameters)\n- [Dependencies](#dependencies)\n- [Troubleshooting](#troubleshooting)\n- [Contributors](#contributors)\n- [License](#license)\n\n## Features\n\n- Generate `cURL` commands for HTTP requests.\n- Support for all major HTTP methods (GET, POST, PUT, DELETE, etc.).\n- Add HTTP headers, body data (JSON or plain text), and query parameters.\n- Support for file uploads via multipart form data.\n- Cookie handling with simple key-value pairs.\n- Additional cURL options like --insecure, --compressed, --verbose, etc.\n- Mask sensitive information like auth tokens and API keys.\n- Format output with line breaks for better readability.\n- Integration with popular HTTP client libraries (Dio, http).\n- Global configuration for consistent behavior.\n- Custom logging functionality.\n- Robust input validation and error handling.\n- Shell-safe escaping of special characters to prevent command injection.\n- Optionally log the generated `cURL` command using Flutter's `debugPrint`.\n\n## Installation\n\nTo use this package, add the following to your `pubspec.yaml` file:\n\n```yaml\ndependencies:\n  log_curl_request: ^1.0.0\n```\n\nThen, run:\n\n```bash\nflutter pub get\n```\n\n## Usage\n\nImport the package into your Dart file:\n\n```dart\nimport 'package:log_curl_request/log_curl_request.dart';\n```\n\nGenerate a basic `cURL` command:\n\n```dart\nString curlCommand = LogCurlRequest.create(\n  \"POST\",\n  \"https://api.example.com/resource\",\n  parameters: {\"key\": \"value\"},\n  data: {\"field\": \"value\"},\n  headers: {\"Authorization\": \"Bearer YOUR_TOKEN\"},\n  showDebugPrint: true,\n);\n```\n\nThis will generate and optionally log a `cURL` command like:\n\n```bash\ncurl -X POST -H \"Authorization: Bearer YOUR_TOKEN\" --data '{\"field\":\"value\"}' \"https://api.example.com/resource?key=value\"\n```\n\n## Example\n\nHere's a basic example of using the package:\n\n```dart\nvoid main() {\n  String curlCommand = LogCurlRequest.create(\n    \"GET\",\n    \"https://api.example.com/users\",\n    parameters: {\"page\": \"1\", \"limit\": \"10\"},\n    headers: {\"Content-Type\": \"application/json\"},\n    showDebugPrint: true,\n  );\n\n  print(curlCommand);\n}\n```\n\nExpected Output (logged via `debugPrint`):\n\n```bash\ncURL command: \ncurl -X GET -H \"Content-Type: application/json\" \"https://api.example.com/users?page=1\u0026limit=10\"\n```\n\n## Advanced Features\n\n### File Uploads\n\nYou can use the `formData` parameter to simulate file uploads:\n\n```dart\nimport 'dart:io';\n\nfinal file = File('/path/to/file.jpg');\nString curlCommand = LogCurlRequest.create(\n  \"POST\",\n  \"https://api.example.com/upload\",\n  formData: {\n    \"file\": file,\n    \"description\": \"My uploaded file\",\n  },\n);\n```\n\nThis will generate a command like:\n\n```bash\ncurl -X POST -F \"file=@/path/to/file.jpg\" -F \"description=My uploaded file\" \"https://api.example.com/upload\"\n```\n\n### Cookies\n\nTo include cookies in your request:\n\n```dart\nString curlCommand = LogCurlRequest.create(\n  \"GET\",\n  \"https://api.example.com/profile\",\n  cookies: {\n    \"session\": \"abc123\",\n    \"theme\": \"dark\",\n  },\n);\n```\n\nThis will generate:\n\n```bash\ncurl -X GET -b \"session=abc123; theme=dark\" \"https://api.example.com/profile\"\n```\n\n### cURL Options\n\nYou can specify additional cURL options:\n\n```dart\nString curlCommand = LogCurlRequest.create(\n  \"GET\",\n  \"https://api.example.com/secure\",\n  curlOptions: CurlOptions(\n    insecure: true,\n    compressed: true,\n    verbose: true,\n    location: true,\n    maxTime: 30,\n    customOptions: [\"--http2\"],\n  ),\n);\n```\n\nThis will generate:\n\n```bash\ncurl -X GET --insecure --compressed --verbose --location --max-time 30 --http2 \"https://api.example.com/secure\"\n```\n\n### Masking Sensitive Information\n\nTo mask sensitive information like authorization tokens:\n\n```dart\nString curlCommand = LogCurlRequest.create(\n  \"GET\",\n  \"https://api.example.com/user\",\n  headers: {\n    \"Authorization\": \"Bearer secret-token-12345\",\n    \"x-api-key\": \"private-api-key\",\n  },\n  maskSensitiveInfo: true,\n);\n```\n\nThis will generate:\n\n```bash\ncurl -X GET -H \"Authorization: ********\" -H \"x-api-key: ********\" \"https://api.example.com/user\"\n```\n\n### Formatted Output\n\nFor better readability, especially for complex requests:\n\n```dart\nString curlCommand = LogCurlRequest.create(\n  \"POST\",\n  \"https://api.example.com/complex\",\n  headers: {\n    \"Content-Type\": \"application/json\",\n    \"Authorization\": \"Bearer token\",\n  },\n  data: {\"key\": \"value\"},\n  formatOutput: true,\n);\n```\n\nThis will generate:\n\n```bash\ncurl -X POST \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer token\" \\\n  --data '{\"key\":\"value\"}' \\\n  \"https://api.example.com/complex\"\n```\n\n### HTTP Client Integration\n\nThe package provides interceptors for popular HTTP clients:\n\n#### Dio\n\n```dart\nimport 'package:dio/dio.dart';\n\nfinal dio = Dio();\ndio.interceptors.add(\n  InterceptorsWrapper(\n    onRequest: (options, handler) {\n      LogCurlInterceptor.fromDioRequest(\n        options,\n        formatOutput: true,\n        maskSensitiveInfo: true,\n      );\n      return handler.next(options);\n    },\n  ),\n);\n```\n\n#### HTTP Package\n\n```dart\nimport 'package:http/http.dart' as http;\n\nfinal request = http.Request('GET', Uri.parse('https://example.com'));\nrequest.headers['Content-Type'] = 'application/json';\n\n// Log the cURL command before sending\nLogCurlInterceptor.fromHttpRequest(\n  request,\n  formatOutput: true,\n  maskSensitiveInfo: true,\n);\n\nfinal response = await request.send();\n```\n\n## Global Configuration\n\nYou can set up global configuration for consistent behavior across your app:\n\n```dart\nvoid main() {\n  // Configure once at the start of your app\n  LogCurlConfig.instance.defaultShowDebugPrint = true;\n  LogCurlConfig.instance.defaultMaskSensitiveInfo = true;\n  LogCurlConfig.instance.defaultFormatOutput = true;\n  LogCurlConfig.instance.defaultCurlOptions = CurlOptions(\n    insecure: true,\n    compressed: true,\n  );\n  \n  // Add custom sensitive headers if needed\n  LogCurlConfig.instance.sensitiveHeaders.add('my-custom-auth-header');\n  \n  // Now any call to LogCurlRequest.create will use these defaults\n  // unless overridden in the specific call\n  runApp(MyApp());\n}\n```\n\n### Custom Logging\n\nYou can customize how cURL commands are logged:\n\n```dart\n// Define a custom logger\nLogCurlConfig.instance.loggerFunction = (message) {\n  // Use your own logging framework\n  MyLogger.debug(message);\n  \n  // Or save to a file\n  LogFile.append(message);\n  \n  // Or send to a remote logging service\n  AnalyticsService.logNetworkRequest(message);\n};\n```\n\n### Default Settings\n\nCreating a custom configuration:\n\n```dart\n// Create a custom configuration\nfinal config = LogCurlConfig(\n  defaultShowDebugPrint: false,\n  defaultMaskSensitiveInfo: true,\n  defaultFormatOutput: true,\n  sensitiveHeaders: ['authorization', 'x-api-key', 'my-custom-header'],\n  loggerFunction: (message) =\u003e print('NETWORK: $message'),\n);\n\n// Set as the global instance\nLogCurlConfig.instance = config;\n```\n\n## Error Handling\n\nThe package provides robust error handling for common problems:\n\n```dart\ntry {\n  final curlCommand = LogCurlRequest.create(\n    \"POST\",\n    \"https://api.example.com\",\n    data: complexObject, // Could cause a JSON encoding error\n  );\n} catch (e) {\n  if (e is ArgumentError) {\n    print('Invalid request parameters: ${e.message}');\n  } else {\n    print('An unexpected error occurred: $e');\n  }\n}\n```\n\nCommon validation errors:\n\n- Empty method or URL\n- Invalid URL format (missing scheme)\n- Invalid data type (not Map or String)\n- JSON encoding failure for data\n- Query parameter processing errors\n\n## Configuration Parameters\n\n- **method**: The HTTP method (e.g., `GET`, `POST`).\n- **path**: The API endpoint (must be a valid URL with scheme).\n- **parameters**: (Optional) Query parameters as a `Map\u003cString, dynamic\u003e`.\n- **data**: (Optional) The request body (supports `Map` or `String`).\n- **headers**: (Optional) HTTP headers as a `Map\u003cString, dynamic\u003e`.\n- **showDebugPrint**: (Optional) A boolean to enable logging of the generated `cURL` command.\n- **cookies**: (Optional) Cookies as a `Map\u003cString, String\u003e`.\n- **formData**: (Optional) Form data including files as a `Map\u003cString, dynamic\u003e`.\n- **curlOptions**: (Optional) Additional cURL options using the `CurlOptions` class.\n- **maskSensitiveInfo**: (Optional) Whether to mask sensitive information like auth tokens.\n- **formatOutput**: (Optional) Whether to format the output with line breaks for readability.\n\n## Dependencies\n\n- `dart:convert`\n- `dart:io`\n- `package:flutter/foundation.dart`\n\nEnsure you have Flutter SDK installed and set up in your development environment.\n\n## Troubleshooting\n\n- **Issue**: `cURL` command not logging.\n  - **Solution**: Ensure `showDebugPrint` is set to `true` or check your custom logger function.\n  \n- **Issue**: Malformed `cURL` command.\n  - **Solution**: Verify the data format and parameter types passed to the method.\n\n- **Issue**: Issues with file uploads.\n  - **Solution**: Ensure the File object exists and has read permissions.\n  \n- **Issue**: Interceptors not working with HTTP clients.\n  - **Solution**: Make sure you have the respective HTTP client packages installed and properly configured.\n\n- **Issue**: ArgumentError is thrown.\n  - **Solution**: Check the error message for details about the validation failure (empty method, invalid URL, etc.).\n\n## Contributors\n\nThis package was authored by [Your Name/Team]. Contributions are welcome. Please submit issues and pull requests on the GitHub repository.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE). See the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoein-dev%2Flog_curl_request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoein-dev%2Flog_curl_request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoein-dev%2Flog_curl_request/lists"}