CloudflareApi.RateLimitRetry (cloudflare_api v0.6.0)

View Source

Retry helper for handling Cloudflare 429 rate-limit responses.

This module can be used directly to wrap an individual request or as a Tesla middleware when building a client:

client = CloudflareApi.new("token", rate_limit_retry: true)
{:ok, %Tesla.Env{status: 200}} = Tesla.get(client, "/zones")

You can also call run/2 around a specific request:

CloudflareApi.RateLimitRetry.run(
  fn -> Tesla.get(client, "/zones") end,
  max_retries: 2,
  sleep: fn _ -> :ok end
)

Retries are bounded (max_retries), default to idempotent methods, and honor the Retry-After header when Cloudflare provides it.

Summary

Functions

Execute request_fun and retry on 429 responses using the provided options.

Functions

run(request_fun, opts \\ [])

Execute request_fun and retry on 429 responses using the provided options.

request_fun should return the same shape as Tesla calls ({:ok, %Tesla.Env{}} | {:error, term}).