Skip to content

ddieruf/cloudflare-client-csharp

Repository files navigation

cloudflare-client-csharp

This is a C# .NETStandard 2.1 client of the endpoints that I needed for v4 of the CloudFlare api.

Endpoints Implemented

User (CloudFlare ref): Get Details, Update

Zone (CloudFlare ref): Create, Get Details, Delete, List

Load Balancer (CloudFlare ref): Create, Get Details, Delete, List

Load Balancer Pool (CloudFlare ref): Create, Get Details, Delete, List, Add Origin, Delete Origin, Set Minimum Origins

Load Balancer Monitor (CloudFlare ref): Create, Get Details, Delete, List

Get Started

To use this library first add it to your C# project

$ dotnet add package CloudflareClient

Set your CloudFlare API credentials. Refer to the API keys area of the CloudFlare docs for more info.

var _xAuthEmail = "<YOUR_EMAIL>";
var _xAuthKey = "<YOUR_KEY>";

Create an instance of the client and construct the desired endpoint class.

var apiClient = new ApiClient(new Configuration(_xAuthEmail,_xAuthKey));
var loadBalancerPoolApi = new LoadBalancerPoolApi(apiClient);

Make a call to an endpoint

var loadBalancerPools = await loadBalancerPoolApi.ListLoadBalancerPoolsAsync();

Features

The client uses RestSharp for all HTTP interactions. The design has been influenced by the patterns in openapi-generator C# template as well as the kubernetes C# client.

Along with the obvious crud actions the load balancer pool object has some added benefits.

  1. Re-balance origin weight: when an origin is added/removed, equal weight can be (optionally) recalculated between all of them.
  2. Logical pool validation: when any change or additions are made to a pool, they are validated for logic. Things like is there at least 1 origin, and is the minimum origin equal to or less than the origin count.

Unless overridden, the client will assume a base path of https://api.cloudflare.com/client/v4.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published