HttpClientToCurl 2.0.8

dotnet add package HttpClientToCurl --version 2.0.8
                    
NuGet\Install-Package HttpClientToCurl -Version 2.0.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HttpClientToCurl" Version="2.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HttpClientToCurl" Version="2.0.8" />
                    
Directory.Packages.props
<PackageReference Include="HttpClientToCurl" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HttpClientToCurl --version 2.0.8
                    
#r "nuget: HttpClientToCurl, 2.0.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HttpClientToCurl@2.0.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HttpClientToCurl&version=2.0.8
                    
Install as a Cake Addin
#tool nuget:?package=HttpClientToCurl&version=2.0.8
                    
Install as a Cake Tool

๐Ÿฅ‡ HttpClientToCurl

Generate curl commands directly from your HttpClient or HttpRequestMessage in .NET โ€” perfect for debugging, logging, and sharing HTTP requests.


๐Ÿ’– Love HttpClientToCurl? Please support us!

If this project has made your life easier, consider buying us a coffee or sending a donation.
Every bit of support keeps us motivated, helps us add new features, fix bugs, and maintain the project โ€” keeping it free and awesome for everyone! โ˜•๐Ÿš€

USDT (Tether โ€“ BEP20 / Binance Smart Chain) wallet address:
0x9d03Be8B979453bE300724FD4bb3eF77517d45AE


๐Ÿ“Š Badges

license stars NuGet Version NuGet Downloads Build


๐Ÿ“– Overview

HttpClientToCurl is a lightweight and powerful .NET extension library that turns your HTTP requests into curl commands. It works with both HttpClient and HttpRequestMessage, giving you two simple ways to generate curl commands:


๐Ÿงฐ 1. Manual Mode

Generate curl commands on demand using extension methods on either HttpClient or HttpRequestMessage.

Best for:
Debugging individual requests, creating reproducible Postman calls, or sharing API examples.


๐Ÿงฉ 2. Automatic Mode

Automatically generates curl output whenever your app sends a request.
You can configure it through dependency injection:

  • Global Registration โ€” enable for all HttpClient instances created via IHttpClientFactory
  • Per-Client Registration โ€” enable only for selected clients

Best for:
Logging, monitoring, or tracing outgoing requests across the application.


๐Ÿ’ก Why Use HttpClientToCurl?

  • ๐Ÿงช Instantly visualise and debug request payloads or headers
  • ๐Ÿค Share exact API calls with teammates or QA engineers
  • โš™๏ธ Simplify Postman and CLI reproduction
  • ๐Ÿงฉ Lightweight, dependency-free, and easy to integrate

โš™๏ธ Installation

dotnet add package HttpClientToCurl

Or visit the NuGet page here: <a href="https://www.nuget.org/packages/HttpClientToCurl" target="_blank">HttpClientToCurl</a>

๐Ÿ“š Documentation

For full examples, detailed usage, and advanced configuration options, please see the Wiki:

๐Ÿ‘‰ Open Wiki โ†’ More Details


๐Ÿš€ Quick Start

๐Ÿงฐ Manual Mode Usage Example

using System.Text;
using HttpClientToCurl;

class Program
{
    static async Task Main()
    {
        var baseAddress = new Uri("http://localhost:1213/v1/");
        var requestUri = "api/test";

        using var httpClientInstance = new HttpClient { BaseAddress = baseAddress };

        string requestBody = @"{""name"":""sara"",""requestId"":10001001,""amount"":20000}";
        var httpRequestMessageInstance = new HttpRequestMessage(HttpMethod.Post, requestUri)
        {
            Content = new StringContent(requestBody, Encoding.UTF8, "application/json")
        };
        httpRequestMessageInstance.Headers.Add("Authorization", "Bearer YourAccessToken");

        // Option 1: Generate curl from HttpClient
        httpClientInstance.GenerateCurlInConsole(httpRequestMessageInstance);

        // Option 2: Generate curl from HttpRequestMessage
        httpRequestMessageInstance.GenerateCurlInConsole(baseAddress);

        await httpClientInstance.SendAsync(httpRequestMessageInstance);
    }
}

โœ… Example Output

curl -X POST 'http://localhost:1213/v1/api/test' \
  -H 'Authorization: Bearer YourAccessToken' \
  -H 'Content-Type: application/json; charset=utf-8' \
  -d '{"name":"sara","requestId":10001001,"amount":20000}'

๐Ÿงฉ Automatic Mode Usage Example

1๏ธโƒฃ Per-Client Registration

Enable curl logging for specific named clients only.

Program.cs / Startup.cs

using HttpClientToCurl;

// Register the curl generator once
builder.Services.AddHttpClientToCurl(builder.Configuration);

// Enable curl logging for selected clients
builder.Services.AddHttpClient("my-client1", showCurl: true);

appsettings.json

"HttpClientToCurl": {
  "Enable": true, // Master switch: enable or disable the entire HttpClientToCURL logging system

  "ShowOnConsole": {
    "TurnOn": true, // Enable console output for generated curl commands
    "NeedAddDefaultHeaders": true, // Include default headers (like User-Agent, Accept, etc.) in the curl output
    "EnableCompression": false, // Compress the console log output (not recommended for debugging readability)
    "EnableCodeBeautification": true // Beautify and format the curl command for better readability
  },

  "SaveToFile": {
    "TurnOn": true, // Enable saving the generated curl commands into a file   
    "NeedAddDefaultHeaders": true, // Include default headers (like User-Agent, Accept, etc.) in the curl output
    "EnableCompression": false, // Compress the saved file (useful if logging a large number of requests)
    "Filename": "curl_commands", // Name of the output file without extension (e.g., will produce curl_commands.log)
    "Path": "C:\\Users\\Public" // Directory path where the log file will be created
  }
}

2๏ธโƒฃ Global Registration

Enable curl generation globally โ€” every HttpClient created through IHttpClientFactory will automatically log curl commands.

Program.cs / Startup.cs

using HttpClientToCurl;

// Register global curl generation
builder.Services.AddAllHttpClientToCurl(builder.Configuration);

// Register default HttpClient (now curl-enabled)
builder.Services.AddHttpClient();

appsettings.json (same configuration options as above)


๐Ÿงฉ Features

Feature Description
๐Ÿ” Methods Supports GET, POST, PUT, PATCH, DELETE
๐Ÿง  Content Types JSON, XML, FormUrlEncodedContent
๐Ÿ’พ Output Console โ€ข File โ€ข String
๐ŸŽจ Beautified Output Optional pretty printing

๐Ÿ“š Articles

๐Ÿ’ก Contribute

Found a bug or want to improve this project? Open an issue or submit a pull request.

๐Ÿ“ง Contact: amin.golmahalle@gmail.com

โญ Give a Star

If you find this project helpful, please give it a โญ โ€” it helps others discover it too!

๐Ÿ™Œ Contributors

<a href="https://github.com/amingolmahalle/HttpClientToCurlGenerator/graphs/contributors"> <img src="https://contrib.rocks/image?repo=amingolmahalle/HttpClientToCurlGenerator" /> </a>

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on HttpClientToCurl:

Package Downloads
SomeGenericDev.RestSharpToCurl

A tiny and hacky library that uses reflection and DelegatingHandlers to generate a cURL script out of RestSharp's requests.

PubSea.Framework

It is a Domain Driven Design Framework, including contracts for creating unified rest api and some helpers.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on HttpClientToCurl:

Repository Stars
Reaparr/Reaparr
Plex downloader that brings content from any server to yours!
Version Downloads Last Updated
2.0.8 171 12/13/2025
2.0.7 62,338 8/21/2025
2.0.6 769,521 3/13/2024
2.0.5 39,098 1/19/2024
2.0.3 10,694 12/20/2023
2.0.2 97,207 10/1/2023
2.0.1 6,311 8/13/2023
2.0.0 20,297 5/25/2023
1.9.0 23,382 3/13/2023
1.8.9 702 3/1/2023
1.8.8 3,113 2/9/2023
1.8.7 721 2/7/2023
1.8.6 668 2/6/2023
1.8.5 705 1/25/2023
1.8.3 1,035 11/23/2022
1.8.2 749 10/31/2022
1.8.1 850 9/19/2022
1.8.0 883 9/19/2022
1.7.0 893 9/13/2022
1.6.0 815 9/13/2022
1.5.0 871 9/11/2022
1.4.0 835 9/10/2022
1.3.0 808 9/6/2022
1.2.0 822 9/5/2022
1.1.0 805 9/5/2022
1.0.0 1,443 9/1/2022

2.0.8