Skip to content

Latest commit

 

History

History
75 lines (59 loc) · 2.62 KB

README.md

File metadata and controls

75 lines (59 loc) · 2.62 KB

Kenc.Cloudflare

Build Status Feature Requests Bugs NuGet

Free and open implementation of the Cloudflare API prtocol v4 in C# .net core, allowing cross-platform automated interaction with Cloudflare.

Getting Started

Install the Nuget package.

Add configuration:

{
  "ApiKey": "<your api key here>",
  "Username": "[email protected]",
  "Endpoint": "https://api.cloudflare.test/client/v4/"
}

Register with dependency injection:

serviceCollection.AddHttpClient();
serviceCollection.AddCloudflareClient(configuration);
private readonly ICloudflareClient cloudflareClient;
public SomeConstructor(ICloudflareClient cloudflareClient) {
  this.cloudflareClient = cloudflareClient ?? throw new ArgumentNullException(nameof(cloudflareClient));
}

public void DoSomething() {
  var zone = await cloudflareClient.Zones.GetAsync("kenc.dk");
}

Not using dependency injection? See IntegrationTests.cs for an example on how to create a client.

Get a specific Zone

var zone = await cloudflareClient.Zones.GetAsync("kenc.dk");

Add a TXT record to the zone

DNSRecord dnsRecord;
try
{
  dnsRecord = await cloudflareClient.ZoneDNSSettingsClient.CreateRecordAsync(zone.Id, "_dummyrecord", DNSRecordType.TXT, "TXT record entry value", 3600);
  return dnsRecord.Id;
}
catch (CloudflareException exception) when (exception.Errors[0].Code == "81057")
{
    Program.LogLine("The DNS entry already exists.");
    return string.Empty;
}

Feedback

Related Projects

Kenc.AcmeLib Library for interacting with ACME-based certificate providers, incl. LetsEncrypt.

License

Licensed under the MIT License.