An extension for generating the CURL script from HttpClient
and HttpRequestMessage
in .NET.
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 requestsHttpRequestMessage
— 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
dotnet add package HttpClientToCurl
Or visit the NuGet page here: HttpClientToCurl
For full examples, detailed usage, and advanced configuration options, please see the Wiki:
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);
}
}
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}'
Works with GET, POST, PUT, PATCH, and DELETE
Supports JSON, XML, and FormUrlEncodedContent
Console / String / File
- How to Generate cURL Script of the HttpClient in .NET
- New Feature in HttpClientToCurl for .NET: Debugging HttpRequestMessage Made Easy
Found a bug or want to improve this project? Open an issue or submit a pull request.
📧 Contact: [email protected]
If you find this project helpful, please give it a ⭐ — it helps others discover it too!