Drunk.Cf.Dns 1.0.2

dotnet add package Drunk.Cf.Dns --version 1.0.2                
NuGet\Install-Package Drunk.Cf.Dns -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Drunk.Cf.Dns" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Drunk.Cf.Dns --version 1.0.2                
#r "nuget: Drunk.Cf.Dns, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Drunk.Cf.Dns as a Cake Addin
#addin nuget:?package=Drunk.Cf.Dns&version=1.0.2

// Install Drunk.Cf.Dns as a Cake Tool
#tool nuget:?package=Drunk.Cf.Dns&version=1.0.2                

Drunk.Cf.Dns

Drunk.Cf.Dns is a .NET library that provides a client for interacting with Cloudflare's DNS API. It leverages Refit to create a strongly-typed, easy-to-use HTTP client.

Features

  • List DNS records
  • Find DNS records by name
  • Create new DNS records
  • Update existing DNS records
  • Delete DNS records

Installation

You can install the package via NuGet:

dotnet add package Drunk.Cf.Dns

Usage

Configuration

First, you need to configure the Cloudflare DNS client in your IServiceCollection:

using Microsoft.Extensions.DependencyInjection;
using Drunk.Cf.Dns;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddCloudflareDnsClient(provider => ("your-email@example.com", "your-api-token"));
    }
}

Creating the Client

You can create the client manually if you prefer:

using Drunk.Cf.Dns;

var client = CfDnsConfigs.Create("your-email@example.com", "your-api-token");

Using the Client

Here are some examples of how to use the client:

List DNS Records
var zoneId = "your-zone-id";
var dnsRecords = await client.ListAsync(zoneId);

if (dnsRecords.Success)
{
    foreach (var record in dnsRecords.Result)
    {
        Console.WriteLine($"{record.Name} - {record.Type} - {record.Content}");
    }
}
Find DNS Records by Name
var zoneId = "your-zone-id";
var name = "example.com";
var dnsRecords = await client.FindByNameAsync(zoneId, name);

if (dnsRecords.Success)
{
    foreach (var record in dnsRecords.Result)
    {
        Console.WriteLine($"{record.Name} - {record.Type} - {record.Content}");
    }
}
Create a DNS Record
var zoneId = "your-zone-id";
var newRecord = new DnsRecord
{
    Type = RecordType.A,
    Name = "example.com",
    Content = "192.0.2.1",
    Ttl = 3600,
    Proxied = false
};

var createResponse = await client.CreateAsync(zoneId, newRecord);

if (createResponse.Success)
{
    Console.WriteLine($"Created record with ID: {createResponse.Result.Id}");
}
Update a DNS Record
var zoneId = "your-zone-id";
var recordId = "your-record-id";
var updatedRecord = new DnsRecord
{
    Type = RecordType.A,
    Name = "example.com",
    Content = "192.0.2.2",
    Ttl = 3600,
    Proxied = false
};

var updateResponse = await client.UpdateAsync(zoneId, recordId, updatedRecord);

if (updateResponse.Success)
{
    Console.WriteLine($"Updated record with ID: {updateResponse.Result.Id}");
}
Delete a DNS Record
var zoneId = "your-zone-id";
var recordId = "your-record-id";

await client.DeleteAsync(zoneId, recordId);

Console.WriteLine("Record deleted successfully.");

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 96 9/8/2024
1.0.1 108 9/8/2024