{"id":15011655,"url":"https://github.com/amingolmahalle/httpclienttocurlgenerator","last_synced_at":"2025-12-24T16:11:11.348Z","repository":{"id":63671516,"uuid":"530583766","full_name":"amingolmahalle/HttpClientToCurlGenerator","owner":"amingolmahalle","description":"The HttpClientToCurl is a NuGet package for generating curl script of HttpClient in .NET ( C# | CSharp | Dotnet ) supported features: Post, Get, Put, and Delete. content types: application/json, text/xml,  application/x-www-form-urlencoded","archived":false,"fork":false,"pushed_at":"2025-01-31T09:53:36.000Z","size":232,"stargazers_count":73,"open_issues_count":3,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-16T11:05:41.105Z","etag":null,"topics":["asp-net","asp-net-core","aspnetcore","codegenerator","converter","csharp","curl","dotnet","dotnet-standard","extension","http","httpclient","json","nuget","nuget-package","package","parser","postman","xml"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/HttpClientToCurl","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/amingolmahalle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2022-08-30T09:22:27.000Z","updated_at":"2025-05-16T02:27:17.000Z","dependencies_parsed_at":"2023-11-19T21:29:39.169Z","dependency_job_id":"1d343218-4039-41d5-ac79-422ceddae313","html_url":"https://github.com/amingolmahalle/HttpClientToCurlGenerator","commit_stats":{"total_commits":156,"total_committers":13,"mean_commits":12.0,"dds":0.7243589743589743,"last_synced_commit":"458b0d48ae6fc397885d0fe3a774d68f3391104d"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amingolmahalle%2FHttpClientToCurlGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amingolmahalle%2FHttpClientToCurlGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amingolmahalle%2FHttpClientToCurlGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amingolmahalle%2FHttpClientToCurlGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amingolmahalle","download_url":"https://codeload.github.com/amingolmahalle/HttpClientToCurlGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518383,"owners_count":22084374,"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":["asp-net","asp-net-core","aspnetcore","codegenerator","converter","csharp","curl","dotnet","dotnet-standard","extension","http","httpclient","json","nuget","nuget-package","package","parser","postman","xml"],"created_at":"2024-09-24T19:41:24.098Z","updated_at":"2025-12-24T16:11:11.342Z","avatar_url":"https://github.com/amingolmahalle.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🥇 HttpClientToCurl\n\nGenerate curl commands directly from your `HttpClient` or `HttpRequestMessage` in .NET — perfect for debugging, logging, and sharing HTTP requests.\n\n### 📊 Badges\n[![license](https://img.shields.io/github/license/amingolmahalle/HttpClientToCurlGenerator)](https://github.com/amingolmahalle/HttpClientToCurlGenerator/blob/master/LICENSE)\n[![stars](https://img.shields.io/github/stars/amingolmahalle/HttpClientToCurlGenerator)](https://github.com/amingolmahalle/HttpClientToCurlGenerator/stargazers)\n[![NuGet Version](https://img.shields.io/nuget/v/HttpClientToCurl.svg)](https://www.nuget.org/packages/HttpClientToCurl/)\n[![NuGet Downloads](https://img.shields.io/nuget/dt/HttpClientToCurl.svg?style=flat-square)](https://www.nuget.org/packages/HttpClientToCurl/)\n![Build](https://github.com/amingolmahalle/HttpClientToCurlGenerator/actions/workflows/dotnet.yml/badge.svg)\n\n---\n\n## 📖 Overview\n**HttpClientToCurl** is a lightweight and powerful .NET extension library that turns your HTTP requests into curl commands.\nIt works with both **`HttpClient`** and **`HttpRequestMessage`**, giving you two simple ways to generate curl commands:\n\n---\n\n### 🧰 1. Manual Mode\n\nGenerate curl commands **on demand** using extension methods on either `HttpClient` or `HttpRequestMessage`.\n\n**Best for:**  \nDebugging individual requests, creating reproducible Postman calls, or sharing API examples.\n\n---\n\n### 🧩 2. Automatic Mode\n\nAutomatically generates curl output whenever your app sends a request.  \nYou can configure it through dependency injection:\n\n- **Global Registration** — enable for all `HttpClient` instances created via `IHttpClientFactory`  \n- **Per-Client Registration** — enable only for selected clients  \n\n**Best for:**  \nLogging, monitoring, or tracing outgoing requests across the application.\n\n---\n\n### 💡 Why Use HttpClientToCurl?\n\n- 🧪 Instantly visualise and debug request payloads or headers  \n- 🤝 Share exact API calls with teammates or QA engineers  \n- ⚙️ Simplify Postman and CLI reproduction  \n- 🧩 Lightweight, dependency-free, and easy to integrate  \n\n---\n## ⚙️ Installation\n\n```bash\ndotnet add package HttpClientToCurl\n```\nOr visit the NuGet page here: \u003ca href=\"https://www.nuget.org/packages/HttpClientToCurl\" target=\"_blank\"\u003eHttpClientToCurl\u003c/a\u003e\n\n## 📚 Documentation\n\nFor full examples, detailed usage, and advanced configuration options, please see the **Wiki**:\n\n👉 [Open Wiki → More Details](https://github.com/amingolmahalle/HttpClientToCurlGenerator/wiki)\n\n---\n\n## 🚀 Quick Start\n\n## 🧰 Manual Mode Usage Example\n\n```csharp\nusing System.Text;\nusing HttpClientToCurl;\n\nclass Program\n{\n    static async Task Main()\n    {\n        var baseAddress = new Uri(\"http://localhost:1213/v1/\");\n        var requestUri = \"api/test\";\n\n        using var httpClientInstance = new HttpClient { BaseAddress = baseAddress };\n\n        string requestBody = @\"{\"\"name\"\":\"\"sara\"\",\"\"requestId\"\":10001001,\"\"amount\"\":20000}\";\n        var httpRequestMessageInstance = new HttpRequestMessage(HttpMethod.Post, requestUri)\n        {\n            Content = new StringContent(requestBody, Encoding.UTF8, \"application/json\")\n        };\n        httpRequestMessageInstance.Headers.Add(\"Authorization\", \"Bearer YourAccessToken\");\n\n        // Option 1: Generate curl from HttpClient\n        httpClientInstance.GenerateCurlInConsole(httpRequestMessageInstance);\n\n        // Option 2: Generate curl from HttpRequestMessage\n        httpRequestMessageInstance.GenerateCurlInConsole(baseAddress);\n\n        await httpClientInstance.SendAsync(httpRequestMessageInstance);\n    }\n}\n```\n\n✅ **Example Output**\n```bash\ncurl -X POST 'http://localhost:1213/v1/api/test' \\\n  -H 'Authorization: Bearer YourAccessToken' \\\n  -H 'Content-Type: application/json; charset=utf-8' \\\n  -d '{\"name\":\"sara\",\"requestId\":10001001,\"amount\":20000}'\n```\n\n---\n\n## 🧩 Automatic Mode Usage Example\n\n### 1️⃣ Per-Client Registration\n\nEnable curl logging for specific named clients only.\n\n**Program.cs / Startup.cs**\n```csharp\nusing HttpClientToCurl;\n\n// Register the curl generator once\nbuilder.Services.AddHttpClientToCurl(builder.Configuration);\n\n// Enable curl logging for selected clients\nbuilder.Services.AddHttpClient(\"my-client1\").AddCurlLogging();\n```\n\n**appsettings.json**\n```json\n\"HttpClientToCurl\": {\n  \"Enable\": true, // Master switch: enable or disable the entire HttpClientToCURL logging system\n\n  \"ShowOnConsole\": {\n    \"TurnOn\": true, // Enable console output for generated curl commands\n    \"NeedAddDefaultHeaders\": true, // Include default headers (like User-Agent, Accept, etc.) in the curl output\n    \"EnableCompression\": false, // Compress the console log output (not recommended for debugging readability)\n    \"EnableCodeBeautification\": true // Beautify and format the curl command for better readability\n  },\n\n  \"SaveToFile\": {\n    \"TurnOn\": true, // Enable saving the generated curl commands into a file\n    \"NeedAddDefaultHeaders\": true, // Include default headers (like User-Agent, Accept, etc.) in the curl output\n    \"EnableCompression\": false, // Compress the saved file (useful if logging a large number of requests)\n    \"Filename\": \"curl_commands\", // Name of the output file without extension (e.g., will produce curl_commands.log)\n    \"Path\": \"C:\\\\Users\\\\Public\" // Directory path where the log file will be created\n  },\n\n  \"SendToLogger\": {\n    \"TurnOn\": true, // Enable sending curl commands to ILogger (integrates with Application Insights, Seq, Serilog, etc.)\n    \"NeedAddDefaultHeaders\": true, // Include default headers (like User-Agent, Accept, etc.) in the curl output\n    \"EnableCompression\": false, // Compress the logged output\n    \"LogLevel\": \"Debug\" // Log level: Trace, Debug, Information, Warning, Error, Critical\n  }\n}\n```\n\n---\n\n### 2️⃣ Global Registration\n\nEnable curl generation globally — every `HttpClient` created through `IHttpClientFactory` will automatically log curl commands.\n\n**Program.cs / Startup.cs**\n```csharp\nusing HttpClientToCurl;\n\n// Register global curl generation\nbuilder.Services.AddAllHttpClientToCurl(builder.Configuration);\n\n// Register default HttpClient (now curl-enabled)\nbuilder.Services.AddHttpClient();\n```\n\n**appsettings.json**\n(same configuration options as above)\n\n---\n\n## 🧩 Features\n\n| Feature | Description |\n|----------|--------------|\n| 🔁 Methods | Supports `GET`, `POST`, `PUT`, `PATCH`, `DELETE` |\n| 🧠 Content Types | `JSON`, `XML`, `FormUrlEncodedContent` |\n| 💾 Output | Console • File • String • ILogger |\n| 🎨 Beautified Output | Optional pretty printing |\n| 📊 Logging Integration | Works with Application Insights, Seq, Serilog, and other ILogger providers |\n\n---\n\n## 📚 Articles\n\n- [How to Generate curl Script of the HttpClient in .NET](https://www.c-sharpcorner.com/article/how-to-generate-curl-script-of-the-httpclient-in-net/)\n- [New Feature in HttpClientToCurl for .NET: Debugging HttpRequestMessage Made Easy](https://medium.com/@mozhgan.etaati/new-feature-in-httpclienttocurl-for-net-debugging-httprequestmessage-made-easy-18cb66dd55f0)\n\n---\n\n## 💖 **Love HttpClientToCurl? Please support us!**  \n\nIf this project has made your life easier, consider buying us a coffee or sending a donation.  \nEvery bit of support keeps us motivated, helps us add new features, fix bugs, and maintain the project — keeping it free and awesome for everyone! ☕🚀\n\n*USDT (Tether – BEP20 / Binance Smart Chain) wallet address:*  \n`0x9d03Be8B979453bE300724FD4bb3eF77517d45AE`\n\n---\n\n## 💡 **Contribute**\n\nFound a bug or want to improve this project?\nOpen an issue or submit a pull request.\n\n📧 Contact: amin.golmahalle@gmail.com\n\n## ⭐ **Give a Star**\n\nIf you find this project helpful, please give it a ⭐ — it helps others discover it too!\n\n## 🙌 **Contributors**\n\n\u003ca href=\"https://github.com/amingolmahalle/HttpClientToCurlGenerator/graphs/contributors\"\u003e \u003cimg src=\"https://contrib.rocks/image?repo=amingolmahalle/HttpClientToCurlGenerator\" /\u003e \u003c/a\u003e \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famingolmahalle%2Fhttpclienttocurlgenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famingolmahalle%2Fhttpclienttocurlgenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famingolmahalle%2Fhttpclienttocurlgenerator/lists"}