pub struct CloudflareClient { /* private fields */ }Expand description
Cloudflare API client for DNS record management.
This client provides methods to list, create, update, and delete DNS records in a Cloudflare zone. It’s designed to be cheaply cloneable (via Arc) for use across async tasks.
§Example
let client = CloudflareClient::new(api_token, zone_id);
let records = client.list_dns_records().await?;Implementations§
Source§impl CloudflareClient
impl CloudflareClient
Sourcepub fn new(api_token: String, zone_id: String) -> Self
pub fn new(api_token: String, zone_id: String) -> Self
Create a new Cloudflare API client.
§Arguments
api_token- Cloudflare API token with DNS edit permissionszone_id- The Cloudflare zone ID for the domain to manage
Sourcepub fn with_base_url(
api_token: String,
zone_id: String,
base_url: String,
) -> Self
pub fn with_base_url( api_token: String, zone_id: String, base_url: String, ) -> Self
Create a client with a custom base URL (useful for testing with mock servers).
Sourcepub async fn get_zone_name(&self) -> Result<String, CloudflareError>
pub async fn get_zone_name(&self) -> Result<String, CloudflareError>
Fetch the zone name for the configured zone ID.
Returns the zone name if successful, or falls back to the zone ID if the API request fails.
Sourcepub async fn list_dns_records(&self) -> CloudflareResult<Vec<DnsRecord>>
pub async fn list_dns_records(&self) -> CloudflareResult<Vec<DnsRecord>>
List all DNS records in the configured zone.
Automatically handles pagination by fetching all pages of records.
Sourcepub async fn create_dns_record(
&self,
record: &DnsRecord,
) -> CloudflareResult<DnsRecord>
pub async fn create_dns_record( &self, record: &DnsRecord, ) -> CloudflareResult<DnsRecord>
Create a new DNS record in the configured zone.
Sourcepub async fn update_dns_record(
&self,
record: &DnsRecord,
) -> CloudflareResult<DnsRecord>
pub async fn update_dns_record( &self, record: &DnsRecord, ) -> CloudflareResult<DnsRecord>
Update an existing DNS record.
The record must have an id field set, otherwise returns MissingRecordId.
Sourcepub async fn delete_dns_record(&self, record_id: &str) -> CloudflareResult<()>
pub async fn delete_dns_record(&self, record_id: &str) -> CloudflareResult<()>
Delete a DNS record by its ID.