cloudflarer cloudflarer website

cloudflarer is an R wrapper around the Cloudflare REST API (v4). It provides authenticated request helpers, response unwrapping, paginated list collectors, and a generic cf_request() function so you can call any endpoint, including ones the package does not wrap yet.

Installation

Install the released version from CRAN:

install.packages("cloudflarer")

Or install the development version from GitHub:

# install.packages("pak")
# pak::pak("drmowinckels/cloudflarer")
install.packages("cloudflarer", repos = c('https://drmowinckels.r-universe.dev', 'https://cloud.r-project.org'))

Authentication

cloudflarer supports both Cloudflare credential schemes:

Set whichever you prefer in ~/.Renviron:

# API token (recommended)
CLOUDFLARE_API_TOKEN=your-token-here

# OR Global API Key (legacy)
CLOUDFLARE_EMAIL=you@example.com
CLOUDFLARE_API_KEY=your-global-api-key

Restart R and check the connection:

library(cloudflarer)
cf_sitrep()

See vignette("authentication", package = "cloudflarer") for the full walkthrough.

Usage

library(cloudflarer)

cf_user()
cf_list_accounts()
cf_list_zones()
cf_list_dns_records(zone_id = "abc123")

Calling endpoints that are not wrapped yet

Every endpoint in the Cloudflare API reference is reachable through the generic cf_request() helper, which builds an authenticated request. Pipe it through the httr2 verbs you need, perform it, and unwrap the {success, errors, result, ...} envelope with cf_resp() (which raises a classed cloudflarer_error on failure).

cf_request("user/tokens/verify") |>
  httr2::req_perform() |>
  cf_resp()

cf_request("zones/abc123/dns_records") |>
  httr2::req_method("POST") |>
  httr2::req_body_json(list(
    type    = "A",
    name    = "www.example.com",
    content = "192.0.2.1",
    ttl     = 1,
    proxied = TRUE
  )) |>
  httr2::req_perform() |>
  cf_resp()

For paginated list endpoints, pipe the request into cf_collect():

cf_request("accounts") |> cf_collect(per_page = 50)

Code of Conduct

Please note that the cloudflarer project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.