CurlDotNet Cookbook
Welcome to the CurlDotNet Cookbook! This collection of practical recipes shows you how to accomplish common tasks using CurlDotNet.
What is CurlDotNet?
CurlDotNet is the pure .NET implementation of curl that allows you to execute curl commands directly in C# applications. Simply paste any curl command from documentation, Stack Overflow, or bash scripts, and it works immediately!
Installation
Install CurlDotNet from NuGet: CurlDotNet on NuGet
dotnet add package CurlDotNet
Or via Package Manager:
Install-Package CurlDotNet
Recipe Categories
🍳 Beginner Recipes
Perfect for getting started with CurlDotNet:
- Simple GET Request - Fetch data from an API
- Send JSON Data - POST JSON to an endpoint
- Handle Errors - Robust error handling
- Upload Files - Upload files to servers
- Download Files - Download and save files
- POST Forms - Submit form data
- Call APIs - Build API client applications
🥘 Intermediate Recipes (Coming Soon)
Take your skills to the next level:
- API Client Class - Build reusable API clients
- Retry Logic - Handle transient failures
- Progress Tracking - Monitor upload/download progress
- Session Cookies - Maintain session state
- Rate Limiting - Respect API limits
- File Management - Advanced file operations
🍱 Advanced Patterns (Coming Soon)
Master complex scenarios:
- Pagination - Handle paginated API responses
- Polling - Implement efficient polling
- Webhooks - Build webhook handlers
- Batch Processing - Process multiple requests efficiently
🌍 Real World Examples (Coming Soon)
Complete implementations for popular services:
- GitHub Integration
- Slack Notifications
- Weather API Client
- OAuth Flow Implementation
- Stripe Payments Integration
Quick Examples
Simple GET Request
using CurlDotNet;
var result = await Curl.ExecuteAsync("curl https://api.github.com");
Console.WriteLine(result.Body);
POST with JSON
using CurlDotNet;
var json = "{\"name\":\"John\",\"email\":\"john@example.com\"}";
var result = await Curl.ExecuteAsync($@"
curl -X POST https://api.example.com/users \
-H 'Content-Type: application/json' \
-d '{json}'
");
if (result.IsSuccess)
{
Console.WriteLine("User created successfully!");
}
Download a File
using CurlDotNet;
var result = await Curl.ExecuteAsync(@"
curl -o downloaded.pdf https://example.com/file.pdf
");
if (result.IsSuccess)
{
Console.WriteLine("File downloaded successfully!");
}
How to Use These Recipes
Each recipe in this cookbook:
- Explains the problem it solves
- Shows complete, working code you can copy and paste
- Includes error handling and best practices
- Provides variations for different scenarios
- Links to related recipes for deeper learning
Recipe Structure
Every recipe follows this format:
- 🎯 What You’ll Build - Clear goal description
- 🥘 Ingredients - What you need (packages, time, prerequisites)
- 📖 Explanation - Understanding the concepts
- 🍳 The Recipe - Step-by-step implementation
- 🎨 Complete Examples - Full working programs
- 🐛 Troubleshooting - Common issues and solutions
- 🎓 Best Practices - Professional tips
- 🚀 Next Steps - Where to go from here
Finding the Right Recipe
By Task
- Fetching data? → Simple GET Request
- Sending data? → Send JSON Data
- Uploading files? → Upload Files
- Downloading files? → Download Files
- Submitting forms? → POST Forms
- Building an API client? → Call APIs
- Handling errors? → Handle Errors
By HTTP Method
- GET → Simple GET Request
- POST → Send JSON Data, POST Forms
- PUT/PATCH → Send JSON Data (includes PUT examples)
- DELETE → Call APIs (includes DELETE examples)
By Feature
- Authentication → Call APIs
- Headers → Most recipes include header examples
- Error Handling → Handle Errors
- File Operations → Upload Files, Download Files
Contributing Recipes
We welcome recipe contributions! If you have a useful pattern or example:
- Fork the repository
- Add your recipe following our format
- Submit a pull request
Additional Resources
- Tutorials - Step-by-step learning path
- API Reference - Complete API documentation
- Getting Started Guide - Installation and setup
- Troubleshooting - Common issues and solutions
Support
- Questions? Ask in GitHub Discussions
- Found a bug? Report it on GitHub Issues
- Need help? Check our Troubleshooting Guide
Ready to cook? Start with a Simple GET Request →