CurlDotNet
CurlDotNet.Core
CurlRequestBuilder Class
🎨 Fluent Builder API - Build curl requests programmatically!
For developers who prefer a fluent API over curl command strings. This builder lets you construct HTTP requests using method chaining, perfect for IntelliSense and compile-time checking.
When to use Builder vs Curl String:
- Use Builder - When building requests dynamically, need IntelliSense, or prefer type safety
- Use Curl String - When you have curl commands from docs/examples (paste and go!)
Quick Example:
// Build a request fluently
var result = await CurlRequestBuilder
.Get("https://api.example.com/users")
.WithHeader("Accept", "application/json")
.WithHeader("Authorization", "Bearer token123")
.WithTimeout(TimeSpan.FromSeconds(30))
.ExecuteAsync();
// Same as: curl -H 'Accept: application/json' -H 'Authorization: Bearer token123' --max-time 30 https://api.example.com/users
public class CurlRequestBuilder
Inheritance System.Object 🡒 CurlRequestBuilder
Remarks
The builder provides a type-safe, IntelliSense-friendly way to build HTTP requests. All builder methods return the builder itself for method chaining.
You can convert a builder to a curl command string using ToCurlCommand().
| Methods | |
|---|---|
| Compressed(bool) | Enable compression (gzip, deflate, etc.). |
| Delete(string) | Create a DELETE request builder. |
| Execute() | Execute the request synchronously. |
| ExecuteAsync(CurlSettings, CancellationToken) | Execute the request with custom settings. |
| ExecuteAsync(CancellationToken) | Execute the request asynchronously. |
| FailOnError(bool) | Fail on HTTP errors (like curl -f). |
| FollowRedirects(bool) | Enable following redirects (301, 302, etc.). |
| Get(string) | Create a GET request builder. |
| GetOptions() | Get the underlying options object (for advanced scenarios). |
| Head(string) | Create a HEAD request builder. |
| IncludeHeaders(bool) | Include headers in response output (like curl -i). |
| Insecure(bool) | Ignore SSL certificate errors (not recommended for production!). |
| Patch(string) | Create a PATCH request builder. |
| Post(string) | Create a POST request builder. |
| Put(string) | Create a PUT request builder. |
| Request(string, string) | Create a custom method request builder. |
| SaveToFile(string) | Save response to file (like curl -o). |
| SaveWithRemoteName() | Use remote filename for output (like curl -O). |
| Silent(bool) | Enable silent mode (like curl -s). |
| ToCurlCommand() | Convert this builder to a curl command string. Useful for debugging or logging what will be executed. |
| Verbose(bool) | Enable verbose output (like curl -v). |
| WithAuth(string) | Set custom authentication header. |
| WithBasicAuth(string, string) | Set basic authentication (username:password). |
| WithBearerToken(string) | Set bearer token authentication. |
| WithBinaryData(byte[]) | Add binary data for upload. |
| WithConnectTimeout(TimeSpan) | Set connection timeout. |
| WithCookie(string) | Set cookie string. |
| WithCookieJar(string) | Set cookie jar file path. |
| WithData(string) | Add POST/PUT data as string. |
| WithFile(string, string) | Upload a file. |
| WithFormData(Dictionary<string,string>) | Add form data (application/x-www-form-urlencoded). |
| WithHeader(string, string) | Add a header to the request. |
| WithHeaders(Dictionary<string,string>) | Add multiple headers at once. |
| WithHttpVersion(string) | Set HTTP version (1.0, 1.1, or 2.0). |
| WithJson(object) | Add POST/PUT data as JSON (automatically serializes and sets Content-Type). |
| WithMaxRedirects(int) | Set maximum number of redirects to follow. |
| WithMultipartForm(Dictionary<string,string>, Dictionary<string,string>) | Add multipart form data with file uploads. |
| WithProxy(string) | Set proxy URL. |
| WithProxy(string, string, string) | Set proxy with authentication. |
| WithRange(string) | Set range for partial downloads (like curl -r). |
| WithReferer(string) | Set the Referer header. |
| WithTimeout(TimeSpan) | Set timeout for the entire operation. |
| WithUserAgent(string) | Set the User-Agent header. |