Skip to footer content
.NET HELP

Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF

For developers navigating the gap between quick command line tool scripts and robust .NET code, the friction often lies in translating a working cURL command into a proper HTTP request within C#. Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem.

By combining this tool with Iron Software products like IronPDF or IronXL, you can build powerful pipelines that fetch data via complex API calls and immediately generate professional reports. In this article we'll look at some examples where these tools can work together to take your projects to the next level.

What is CurlDotNet?

CurlDotNet is a pure C# .NET implementation of the industry-standard curl tool. Unlike wrappers that rely on native dependencies or libcurl, this library offers a 100% managed solution with full support for Windows, Linux, macOS, and more. It ensures the same behavior as the standard client, allowing you to simply paste a bash copy of a command from API docs directly into your code.

Quick Start and Installation

To get started, simply run the following command in your project directory:

dotnet add package curldotnet

This installs the package CurlDotNet, giving you access to ready to use recipes for handling web requests without the overhead of HttpClient configuration.

Using Curl-Dot-Net Curl Commands

The library excels at parsing string value commands. If you have a working curl https string from a GitHub API page or internal docs, you can execute it directly.

using CurlDotNet;

// Simply copy-paste your shell command
var command = "curl -X GET https://api.github.com/users/jacob-mellor -H 'User-Agent: curl-dot-net'";
var result = await Curl.ExecuteAsync(command);
Console.WriteLine(result.Body);
using CurlDotNet;

// Simply copy-paste your shell command
var command = "curl -X GET https://api.github.com/users/jacob-mellor -H 'User-Agent: curl-dot-net'";
var result = await Curl.ExecuteAsync(command);
Console.WriteLine(result.Body);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

.NET Code Curl DotNet Output

Output for our first Curl DotNet command

For those who prefer a structured approach, the fluent builder provides a clean API to set headers, curl options, and access tokens.

var response = await Curl.GetAsync("https://api.github.com/users/ironsoftware")
    .WithHeader("Authorization", "Bearer YOUR_TOKEN")
    .WithHeader("X-API-Key", "12345")
    .ExecuteAsync();
var response = await Curl.GetAsync("https://api.github.com/users/ironsoftware")
    .WithHeader("Authorization", "Bearer YOUR_TOKEN")
    .WithHeader("X-API-Key", "12345")
    .ExecuteAsync();
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This flexibility handles TLS handshake mechanics, rate limiting, and error handling internally, mimicking the default behavior of the curl executable.

Integration with IronSoftware in the .NET Framework

The real power unlocks when you pipe the output of CurlDotNet into Iron Software tools. Since CurlDotNet handles the transport layer (fetching JSON, files, or HTML), IronSoftware products can focus on processing that content.

Scenario: Generating PDF Reports from API Data

Imagine you need to download user data from a secure URL and generate a PDF report. The API requires a specific bash signature that is hard to replicate with HttpClient but easy with a curl command.

Step 1: Fetch Data with Curl-Dot-Net

// Define the curl command string with all necessary headers (here we use an example test website)
string curlCmd = "curl https://www.w3.org/TR/html4/ -H 'X-API-Key: secure_key'";

// Execute the request
var result = await Curl.ExecuteAsync(curlCmd);

// Extract the content (assumed to be HTML for this scenario)
string htmlContent = result.Body;
// Define the curl command string with all necessary headers (here we use an example test website)
string curlCmd = "curl https://www.w3.org/TR/html4/ -H 'X-API-Key: secure_key'";

// Execute the request
var result = await Curl.ExecuteAsync(curlCmd);

// Extract the content (assumed to be HTML for this scenario)
string htmlContent = result.Body;
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Step 2: Generate PDF with IronPDF

IronPDF is a powerful library designed to render HTML, CSS, JavaScript, and images into high-fidelity PDF documents. It provides full support for modern web standards and includes features like adding headers, footers, and setting specific rendering options.

using IronPdf;

// Instantiate the renderer
var renderer = new ChromePdfRenderer();

// Convert the fetched HTML data to PDF
var pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Save the file to the output path
pdf.SaveAs("output.pdf");
using IronPdf;

// Instantiate the renderer
var renderer = new ChromePdfRenderer();

// Convert the fetched HTML data to PDF
var pdf = renderer.RenderHtmlAsPdf(htmlContent);

// Save the file to the output path
pdf.SaveAs("output.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

Test website converted to PDF using CurlDotNet and IronPDF

Scenario: Exporting JSON to Excel

If your app consumes a JSON feed, you can fetch it using CurlDotNet's test capabilities and export it using IronXL.

Step 1: Fetch JSON Data with Curl-Dot-Net

We use the fluent builder for clean .NET code to fetch the JSON feed:

string testUrl = "https://jsonplaceholder.typicode.com/users";

Console.WriteLine($"Executing HTTP request to fetch JSON from: {testUrl}");
// Replace the CurlDotNet fluent builder usage with the correct async method
var response = await Curl.GetAsync(testUrl); // Use Curl.GetAsync() for async HTTP GET

string jsonBody = response.Body;
string testUrl = "https://jsonplaceholder.typicode.com/users";

Console.WriteLine($"Executing HTTP request to fetch JSON from: {testUrl}");
// Replace the CurlDotNet fluent builder usage with the correct async method
var response = await Curl.GetAsync(testUrl); // Use Curl.GetAsync() for async HTTP GET

string jsonBody = response.Body;
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Step 2: Load and Export to Excel using IronXL

IronXL is a comprehensive .NET library designed to handle all aspects of reading, writing, and manipulating Excel file formats (.xlsx, .xls, .csv). Crucially, it does this without needing Microsoft Office installed on the server or client machine, making it ideal for cross-platform Linux and CI CD environments. Key features include full support for creating charts, applying formulas, and styling cells.

With the raw JSON data now in a string, IronXL can be used to parse it and build a spreadsheet.

var workbook = WorkBook.Create(ExcelFileFormat.XLSX);
 var sheet = workbook.CreateWorkSheet("User Data");

 // 1. Deserialize the JSON string to a list of UserRecord objects
 Console.WriteLine("Deserializing JSON data...");
 var salesRecords = JsonConvert.DeserializeObject<List<UserRecord>>(jsonBody);

 // 2. Insert the data into the sheet using IronXL's SetCellValue method
 Console.WriteLine("Inserting data into Excel using IronXL...");

 // Write headers
 sheet.SetCellValue(0, 0, "id");
 sheet.SetCellValue(0, 1, "name");
 sheet.SetCellValue(0, 2, "username");
 sheet.SetCellValue(0, 3, "email");

 // Write data rows
 for (int i = 0; i < salesRecords.Count; i++)
 {
     var record = salesRecords[i];
     sheet.SetCellValue(i + 1, 0, record.id);
     sheet.SetCellValue(i + 1, 1, record.name);
     sheet.SetCellValue(i + 1, 2, record.username);
     sheet.SetCellValue(i + 1, 3, record.email);
 }

 // Save the Excel file
 string filePath = "UserReport.xlsx";
 workbook.SaveAs(filePath);

 Console.WriteLine($"\n Success! Excel report saved to: {Path.GetFullPath(filePath)}");
var workbook = WorkBook.Create(ExcelFileFormat.XLSX);
 var sheet = workbook.CreateWorkSheet("User Data");

 // 1. Deserialize the JSON string to a list of UserRecord objects
 Console.WriteLine("Deserializing JSON data...");
 var salesRecords = JsonConvert.DeserializeObject<List<UserRecord>>(jsonBody);

 // 2. Insert the data into the sheet using IronXL's SetCellValue method
 Console.WriteLine("Inserting data into Excel using IronXL...");

 // Write headers
 sheet.SetCellValue(0, 0, "id");
 sheet.SetCellValue(0, 1, "name");
 sheet.SetCellValue(0, 2, "username");
 sheet.SetCellValue(0, 3, "email");

 // Write data rows
 for (int i = 0; i < salesRecords.Count; i++)
 {
     var record = salesRecords[i];
     sheet.SetCellValue(i + 1, 0, record.id);
     sheet.SetCellValue(i + 1, 1, record.name);
     sheet.SetCellValue(i + 1, 2, record.username);
     sheet.SetCellValue(i + 1, 3, record.email);
 }

 // Save the Excel file
 string filePath = "UserReport.xlsx";
 workbook.SaveAs(filePath);

 Console.WriteLine($"\n Success! Excel report saved to: {Path.GetFullPath(filePath)}");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output Excel File

Excel file created with CurlDotNet and IronExcel

Why This Combination?

  1. Cross-Platform Consistency: Both CurlDotNet and IronSoftware products support Windows, Linux, and macOS. This is critical for CI CD pipelines running on runtime environments like Microsoft Azure or AWS Lambda.

  2. Code Generation: Developers often get code generation snippets in bash or shell format. curl-dot-net allows you to use these snippets directly, while IronSoftware handles the heavy lifting of document manipulation.

  3. No Native Dependencies: Because CurlDotNet is a pure C# implementation, you avoid common issues associated with linking external C++ libraries or libcurl binaries on different OS versions.

Conclusion

Jacob Mellor has provided a vital tool for the DotNet community. By allowing developers to use familiar curl options within .NET Framework and Core applications, CurlDotNet simplifies the http request process. When paired with Iron Software, you can create a seamless workflow: fetch data with the precision of curl, and process it with the power of IronPDF or IronXL.

If you encounter issues, be sure to report bugs on the GitHub page to help improve support for every user.

Frequently Asked Questions

What is CurlDotNet?

CurlDotNet is a library created by Jacob Mellor to bring the functionality of cURL to the .NET ecosystem, allowing developers to easily translate cURL commands into .NET code.

How does CurlDotNet help developers?

CurlDotNet helps developers by simplifying the process of translating cURL command-line operations into HTTP requests within C#, making it easier to integrate command-line tool scripts into robust .NET applications.

What problem does CurlDotNet solve?

CurlDotNet solves the problem of friction that developers face when trying to convert working cURL commands into proper HTTP requests in C#. It offers a familiar approach for those accustomed to cURL's simplicity.

Can CurlDotNet be used with IronPDF?

Yes, CurlDotNet can be used alongside IronPDF to enhance the ease of making HTTP requests as part of PDF generation workflows within .NET applications.

Is CurlDotNet suitable for beginners?

Yes, CurlDotNet is suitable for beginners as it provides a familiar command-line style interface that eases the learning curve for those new to .NET and HTTP requests.

What are the benefits of using CurlDotNet with IronPDF?

Using CurlDotNet with IronPDF allows developers to streamline HTTP requests while generating PDFs, improving efficiency and leveraging the strengths of both tools.

Where can I learn more about CurlDotNet?

You can learn more about CurlDotNet by visiting Jacob Mellor's article on Medium, which provides detailed insights into how the library bridges the gap between cURL commands and .NET code.

Jacob Mellor, Chief Technology Officer @ Team Iron
Chief Technology Officer

Jacob Mellor is Chief Technology Officer at Iron Software and a visionary engineer pioneering C# PDF technology. As the original developer behind Iron Software's core codebase, he has shaped the company's product architecture since its inception, transforming it alongside CEO Cameron Rimington into a 50+ person company serving NASA, Tesla, ...

Read More