Kenc.Cloudflare
A modern .NET client library for the Cloudflare API, enabling programmatic management of DNS records, caching rules, and other Cloudflare features.
About the Project
Kenc.Cloudflare is a comprehensive .NET client library for interacting with the Cloudflare API. It enables developers to programmatically manage various Cloudflare services including DNS records, caching rules, Workers, and more.
Key Features
- Strongly-typed models for request and response handling
- Asynchronous API support with cancellation tokens
- Authentication via API tokens or API keys
- Comprehensive error handling and logging
- Support for rate limiting and pagination
Code Examples
For more code samples, checkout the /samples/ folder in the source repository.
Basic Usage
// Create the client with API token authentication
var client = new CloudflareClient(new ApiTokenAuthentication("your-api-token"));
// Get zones (domains)
var zones = await client.Zones.GetZonesAsync();
foreach (var zone in zones)
{
Console.WriteLine($"Zone: {zone.Name}, Status: {zone.Status}");
}
// Get DNS records for a zone
var dnsRecords = await client.Dns.GetDnsRecordsAsync(zones.First().Id);
foreach (var record in dnsRecords)
{
Console.WriteLine($"Record: {record.Name}, Type: {record.Type}, Content: {record.Content}");
}
Adding a DNS Record
// Create the client
var client = new CloudflareClient(new ApiTokenAuthentication("your-api-token"));
// Get the zone ID for your domain
var zones = await client.Zones.GetZonesAsync(new ZoneFilter { Name = "example.com" });
var zoneId = zones.First().Id;
// Create a new DNS record
var newRecord = await client.Dns.CreateDnsRecordAsync(
zoneId,
new DnsRecordCreate
{
Type = "A",
Name = "api",
Content = "192.0.2.1",
Ttl = 120,
Proxied = true
});
Console.WriteLine($"Created record: {newRecord.Id}, {newRecord.Name}");