Crates.io | migamake-api-cloudflare |
lib.rs | migamake-api-cloudflare |
version | 0.2.0 |
source | src |
created_at | 2020-12-23 20:07:31.507349 |
updated_at | 2020-12-29 11:57:04.39555 |
description | A library to work with Cloudflare apis |
homepage | https://gitlab.com/migamake/migamake-hurl/cloudflare-rust-api |
repository | https://gitlab.com/migamake/migamake-hurl/cloudflare-rust-api |
max_upload_size | |
id | 326671 |
size | 26,404 |
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. You can read more about API Tokens. From this document -
API Tokens provide a new way to authenticate with the Cloudflare API. They allow for scoped and permissioned access to resources and use the RFC compliant Authorization Bearer Token Header.
Add this library to an existing project -
cargo add migamake-api-cloudflare
Clone the repository and build the project -
cargo build
To view the documentation locally run -
cargo doc --no-deps --open
To run the unit tests -
cargo test --lib
To run all the tests including the integration tests - ( expects enviornment variables CLOUDFLARE_API_KEY, CLOUDFLARE_DOMAIN and CLOUDFLARE_ZONE )
cargo test
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);
}
}