Skip to content

Commit 2b4652a

Browse files
Revise README for improved clarity and examples
Updated README.md to enhance clarity and detail about the HttpClientToCurl library, including usage examples and installation instructions.
1 parent df31557 commit 2b4652a

File tree

1 file changed

+100
-84
lines changed

1 file changed

+100
-84
lines changed

README.md

Lines changed: 100 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# 🥇 HttpClientToCurl
2-
An extension for generating the **CURL script** from **`HttpClient`** and **`HttpRequestMessage`** in .NET.
32

3+
Generate cURL commands directly from your `HttpClient` or `HttpRequestMessage` in .NET — perfect for debugging, logging, and sharing HTTP requests.
4+
5+
---
6+
7+
### 📊 Badges
48
[![license](https://img.shields.io/github/license/amingolmahalle/HttpClientToCurlGenerator)](https://github.com/amingolmahalle/HttpClientToCurlGenerator/blob/master/LICENSE)
59
[![stars](https://img.shields.io/github/stars/amingolmahalle/HttpClientToCurlGenerator)](https://github.com/amingolmahalle/HttpClientToCurlGenerator/stargazers)
610
[![NuGet Version](https://img.shields.io/nuget/v/HttpClientToCurl.svg)](https://www.nuget.org/packages/HttpClientToCurl/)
@@ -10,114 +14,120 @@ An extension for generating the **CURL script** from **`HttpClient`** and **`Htt
1014
---
1115

1216
## 📖 Overview
13-
**`HttpClientToCurl`** is a lightweight **.NET extension library** that helps you visualize any HTTP request as a **CURL command**.
1417

15-
You can use its extension methods on both:
18+
**HttpClientToCurl** is a lightweight and powerful .NET extension library that turns your HTTP requests into **cURL** commands.
19+
20+
You can use its extension methods on:
1621
- **`HttpClient`** — to generate CURL directly when sending requests
1722
- **`HttpRequestMessage`** — to inspect or log CURL representations before sending
1823

19-
This is useful for:
20-
- Debugging and verifying request payloads or headers
21-
- Sharing API calls between teammates
22-
- Generating or updating Postman collections easily
24+
---
25+
26+
### 🧩 1. Automatic Mode
27+
28+
Automatically generates cURL output whenever your app sends a request.
29+
You can configure it through dependency injection:
30+
31+
- **Global Registration** — enable for all `HttpClient` instances created via `IHttpClientFactory`
32+
- **Per-Client Registration** — enable only for selected clients
33+
34+
**Best for:**
35+
Logging, monitoring, or tracing outgoing requests across the application.
2336

2437
---
38+
39+
### 🧰 2. Manual Mode
40+
41+
Generate cURL commands **on demand** using extension methods on either `HttpClient` or `HttpRequestMessage`.
42+
43+
**Best for:**
44+
Debugging individual requests, creating reproducible Postman calls, or sharing API examples.
45+
46+
---
47+
48+
### 💡 Why Use HttpClientToCurl?
49+
50+
- 🧪 Instantly visualize and debug request payloads or headers
51+
- 🤝 Share exact API calls with teammates or QA engineers
52+
- ⚙️ Simplify Postman and CLI reproduction
53+
- 🪶 Lightweight, dependency-free, and easy to integrate
54+
55+
---
56+
2557
## ⚙️ Installation
2658

59+
Install via NuGet:
60+
2761
```bash
2862
dotnet add package HttpClientToCurl
2963
```
30-
Or visit the NuGet page here: <a href="https://www.nuget.org/packages/HttpClientToCurl" target="_blank">HttpClientToCurl</a>
31-
32-
## 📚 Documentation
3364

34-
For full examples, detailed usage, and advanced configuration options, please see the **Wiki**:
65+
Or visit the [NuGet page →](https://www.nuget.org/packages/HttpClientToCurl)
3566

36-
👉 [Open Wiki → More Details](https://github.com/amingolmahalle/HttpClientToCurlGenerator/wiki)
37-
38-
## 🚀 **Usage Example**
39-
40-
### ⚡ Quick Usage
67+
---
4168

42-
#### 1️⃣ Global Registration
69+
## 🚀 Quick Start
4370

44-
Enable cURL generation globally so that every `HttpClient` created through `IHttpClientFactory` automatically logs cURL commands before sending requests.
71+
### 🔧 1️⃣ Global Registration
4572

46-
**Program.cs / Startup:**
73+
Enable cURL generation globally — every `HttpClient` created through `IHttpClientFactory` will automatically log cURL commands.
4774

75+
**Program.cs / Startup.cs**
4876
```csharp
4977
using HttpClientToCurl;
5078

51-
// Register global cURL generation mode
79+
// Register global cURL generation
5280
builder.Services.AddHttpClientToCurlInGeneralMode(builder.Configuration);
5381

54-
// Register a default HttpClient (now cURL-enabled)
82+
// Register default HttpClient (now cURL-enabled)
5583
builder.Services.AddHttpClient();
5684
```
5785

58-
##### Configuration (via `appsettings.json`)
59-
86+
**appsettings.json**
6087
```json
6188
"HttpClientToCurl": {
62-
"TurnOnAll": true,
63-
64-
"ShowOnConsole": {
65-
"TurnOn": true,
66-
"NeedAddDefaultHeaders": true,
67-
"EnableCompression": false,
68-
"EnableCodeBeautification": true
69-
},
70-
71-
"SaveToFile": {
72-
"TurnOn": true,
73-
"NeedAddDefaultHeaders": true,
74-
"EnableCompression": false,
75-
"Filename": "curl_commands",
76-
"Path": "C:\\Users\\Public"
77-
}
89+
"TurnOnAll": true, // Master switch: enable or disable the entire HttpClientToCURL logging system
90+
91+
"ShowOnConsole": {
92+
"TurnOn": true, // Enable console output for generated curl commands
93+
"NeedAddDefaultHeaders": true, // Include default headers (like User-Agent, Accept, etc.) in the curl output
94+
"EnableCompression": false, // Compress the console log output (not recommended for debugging readability)
95+
"EnableCodeBeautification": true // Beautify and format the curl command for better readability
96+
},
97+
98+
"SaveToFile": {
99+
"TurnOn": true, // Enable saving the generated curl commands into a file
100+
"NeedAddDefaultHeaders": true, // Include default headers (like User-Agent, Accept, etc.) in the curl output
101+
"EnableCompression": false, // Compress the saved file (useful if logging a large number of requests)
102+
"Filename": "curl_commands", // Name of the output file without extension (e.g., will produce curl_commands.log)
103+
"Path": "C:\\Users\\Public" // Directory path where the log file will be created
78104
}
105+
}
79106
```
80107

81-
#### 2️⃣ Specific Registration
108+
---
82109

83-
If you only want cURL generation for specific clients, you can enable it per-client easily using the built-in registration helpers.
110+
### 🔧 2️⃣ Per-Client Registration
84111

85-
**Program.cs / Startup:**
112+
Enable cURL logging for specific named clients only.
86113

114+
**Program.cs / Startup.cs**
87115
```csharp
88116
using HttpClientToCurl;
89117

90-
// Register the cURL generator service once
118+
// Register the cURL generator once
91119
builder.Services.AddHttpClientToCurl(builder.Configuration);
92120

93-
// Then register specific HttpClients with cURL logging enabled
121+
// Enable cURL logging for selected clients
94122
builder.Services.AddHttpClient("my-client1", showCurl: true);
95123
```
96124

97-
##### Configuration (via `appsettings.json`)
125+
**appsettings.json**
126+
(same configuration options as above)
98127

99-
```json
100-
"HttpClientToCurl": {
101-
"TurnOnAll": true,
102-
103-
"ShowOnConsole": {
104-
"TurnOn": true,
105-
"NeedAddDefaultHeaders": true,
106-
"EnableCompression": false,
107-
"EnableCodeBeautification": true
108-
},
109-
110-
"SaveToFile": {
111-
"TurnOn": true,
112-
"NeedAddDefaultHeaders": true,
113-
"EnableCompression": false,
114-
"Filename": "curl_commands",
115-
"Path": "C:\\Users\\Public"
116-
}
117-
}
118-
```
128+
---
119129

120-
### ⚙️ Manual Usage
130+
## 🧰 Manual Usage Example
121131

122132
```csharp
123133
using System.Text;
@@ -127,43 +137,49 @@ class Program
127137
{
128138
static async Task Main()
129139
{
140+
var baseAddress = new Uri("http://localhost:1213/v1/");
130141
var requestUri = "api/test";
131142

132-
using var httpClientInstance = new HttpClient();
133-
var baseAddress = new Uri("http://localhost:1213/v1/");
134-
httpClientInstance.BaseAddress = baseAddress;
135-
string requestBody = /*lang=json,strict*/ @"{""name"":""sara"",""requestId"":10001001,""amount"":20000}";
136-
HttpRequestMessage httpRequestMessageInstance = new(HttpMethod.Post, requestUri);
143+
using var httpClientInstance = new HttpClient { BaseAddress = baseAddress };
144+
145+
string requestBody = @"{""name"":""sara"",""requestId"":10001001,""amount"":20000}";
146+
var httpRequestMessageInstance = new HttpRequestMessage(HttpMethod.Post, requestUri)
147+
{
148+
Content = new StringContent(requestBody, Encoding.UTF8, "application/json")
149+
};
137150
httpRequestMessageInstance.Headers.Add("Authorization", "Bearer YourAccessToken");
138-
httpRequestMessageInstance.Content = new StringContent(requestBody, Encoding.UTF8, "application/json");
139151

140-
// Using the HttpClient extension:
152+
// Option 1: Generate cURL from HttpClient
141153
httpClientInstance.GenerateCurlInConsole(httpRequestMessageInstance);
142154

143-
// Or using the HttpRequestMessage extension:
155+
// Option 2: Generate cURL from HttpRequestMessage
144156
httpRequestMessageInstance.GenerateCurlInConsole(baseAddress);
145157

146158
await httpClientInstance.SendAsync(httpRequestMessageInstance);
147159
}
148160
}
149161
```
150162

151-
## ✅ Output:
152-
163+
**Example Output**
153164
```bash
154-
curl -X POST 'http://localhost:1213/v1/api/test' -H 'Authorization: Bearer YourAccessToken'
155-
-H 'Content-Type: application/json; charset=utf-8' -d '{"name":"sara","requestId":10001001,"amount":20000}'
165+
curl -X POST 'http://localhost:1213/v1/api/test' \
166+
-H 'Authorization: Bearer YourAccessToken' \
167+
-H 'Content-Type: application/json; charset=utf-8' \
168+
-d '{"name":"sara","requestId":10001001,"amount":20000}'
156169
```
157170

158-
## 🧩 **Other Features**
159-
160-
Works with **GET**, **POST**, **PUT**, **PATCH**, and **DELETE**
171+
---
161172

162-
Supports **JSON**, **XML**, and **FormUrlEncodedContent**
173+
## 🧩 Features
163174

164-
## **Output to:**
175+
| Feature | Description |
176+
|----------|--------------|
177+
| 🔁 Methods | Supports `GET`, `POST`, `PUT`, `PATCH`, `DELETE` |
178+
| 🧠 Content Types | JSON, XML, `FormUrlEncodedContent` |
179+
| 💾 Output | Console • File • String |
180+
| 🎨 Beautified Output | Optional pretty printing |
165181

166-
**Console** / **String** / **File**
182+
---
167183

168184
## 📚 Articles
169185

0 commit comments

Comments
 (0)