Skip to content

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

License

Notifications You must be signed in to change notification settings

amingolmahalle/HttpClientToCurlGenerator

Repository files navigation

🥇 HttpClientToCurl

An extension for generating the CURL script from HttpClient and HttpRequestMessage in .NET.

license stars NuGet Version NuGet Downloads Build


📖 Overview

HttpClientToCurl is a lightweight .NET extension library that helps you visualize any HTTP request as a CURL command.

You can use its extension methods on both:

  • HttpClient — to generate CURL directly when sending requests
  • HttpRequestMessage — to inspect or log CURL representations before sending

This is useful for:

  • Debugging and verifying request payloads or headers
  • Sharing API calls between teammates
  • Generating or updating Postman collections easily

⚙️ Installation

dotnet add package HttpClientToCurl

Or visit the NuGet page here: HttpClientToCurl

📚 Documentation

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

👉 Open Wiki → More Details

🚀 Usage Example

using System.Text;
using HttpClientToCurl;

class Program
{
    static async Task Main()
    {
        var requestUri = "api/test";

        using var httpClientInstance = new HttpClient();
        var baseAddress = new Uri("http://localhost:1213/v1/");
        httpClientInstance.BaseAddress = baseAddress;
        string requestBody = /*lang=json,strict*/ @"{""name"":""sara"",""requestId"":10001001,""amount"":20000}";
        HttpRequestMessage httpRequestMessageInstance = new(HttpMethod.Post, requestUri);
        httpRequestMessageInstance.Headers.Add("Authorization", "Bearer YourAccessToken");
        httpRequestMessageInstance.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");

        // Using the HttpClient extension:
        httpClientInstance.GenerateCurlInConsole(httpRequestMessageInstance);

        // Or using the HttpRequestMessage extension:
        httpRequestMessageInstance.GenerateCurlInConsole(baseAddress);

        await httpClientInstance.SendAsync(httpRequestMessageInstance);
    }
}

✅ 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}'

🧩 Other Features

Works with GET, POST, PUT, PATCH, and DELETE

Supports JSON, XML, and FormUrlEncodedContent

Output to:

Console / String / File

📚 Articles

💡 Contribute

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

📧 Contact: [email protected]

Give a Star

If you find this project helpful, please give it a ⭐ — it helps others discover it too!

🙌 Contributors

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 7