Migamake Cloudflare API

This crate is a wrapper for the Cloudflare API. It includes support for 3 endpoints -

This crate uses API token for authentication. The token with appropriate permissions can be created on the cloudflare dashboard.

Installing

cargo install migamake-api-cloudflare

Building

Clone the repository and build the project -

cargo build

Documentation

To view the documentation locally run -

cargo doc --no-deps --open

Running Tests

To run the unit tests -

cargo test --lib

To run all the tests including the integration tests - ( expects enviornment variables CLOUDFLAREAPIKEY, CLOUDFLAREDOMAIN and CLOUDFLAREZONE )

cargo test

Usage

This example demonstrates the usage of the library. The example creates a TXT record.

[dependencies]
migamake-api-cloudflare = { version = "0.1"}

use migamake_api_cloudflare::{Cloudflare, dns};

fn main() {
    let domain = "example.com".into();
    let zoneid = "some id";

    // initializes the object using an environment variable CLOUDFLARE_API_KEY
    // or the api key could be passed to the default method
    // let cloudflare = Cloudflare::default(Some("api-key").into());
    let cloudflare = Cloudflare::default(None);

    let mut txt_dns_record = dns::TXTRecord::new();
    txt_dns_record.name = domain;
    txt_dns_record.content = "create a txt record".into();

    let response = cloudflare.create_dns_record(txt_dns_record, &zoneid);

    let res = response.unwrap();
    if res.success {
        println!("{}", "Record created");
    }
    else{
        println!("{:?}", res.errors);
    }

}