A tiny, zero-dependency client for the Cloudflare REST API v4: attaches a
Bearer token and sends requests over the JDK's java.net.http client. It is
the transport the Images product needs — the counterpart to internal.s3,
but for Cloudflare's own JSON API rather than S3.
It handles two request-body shapes, both hand-rolled so nothing is pulled in:
a JSON body (:json <clj-data>) and a multipart/form-data upload
(:multipart [part …]). It is stateless and carries no per-product knowledge;
callers build paths and interpret responses.
A tiny, zero-dependency client for the Cloudflare REST API v4: attaches a Bearer token and sends requests over the JDK's `java.net.http` client. It is the transport the Images product needs — the counterpart to `internal.s3`, but for Cloudflare's own JSON API rather than S3. It handles two request-body shapes, both hand-rolled so nothing is pulled in: a JSON body (`:json <clj-data>`) and a `multipart/form-data` upload (`:multipart [part …]`). It is stateless and carries no per-product knowledge; callers build paths and interpret responses.
(client {:keys [api-token base-url http-client]
:or {base-url default-base-url}})Build a Cloudflare API client handle. :api-token is the bearer token;
:base-url defaults to the public v4 endpoint. An :http-client may be
supplied to share a JDK client; otherwise one is created.
Build a Cloudflare API client handle. `:api-token` is the bearer token; `:base-url` defaults to the public v4 endpoint. An `:http-client` may be supplied to share a JDK client; otherwise one is created.
(header resp name)First value of response header name (case-insensitive), or nil.
First value of response header `name` (case-insensitive), or nil.
(send-bytes client req)Like send-request, but :body in the result is the raw byte[] — for
binary responses such as an image blob.
Like `send-request`, but `:body` in the result is the raw `byte[]` — for binary responses such as an image blob.
(send-request client req)Sign-free send of one request. req:
:method "GET" | "POST" | "PATCH" | "DELETE"
:path path after the base URL, e.g. "/accounts/ID/images/v1"
:query map of query params (optional; URL-encoded)
:headers map of extra headers (optional)
:json Clojure data to send as a JSON body (optional)
:multipart vector of form parts to send as multipart/form-data (optional)
:body raw byte[] body (optional; ignored if :json/:multipart given)
Returns {:status int :headers {lower-name [vals]} :body <string>} for any
completed exchange (including 4xx/5xx) — the body is decoded as a UTF-8 string
(Cloudflare answers JSON even on errors). Network failures throw IOException.
Sign-free send of one request. `req`:
:method "GET" | "POST" | "PATCH" | "DELETE"
:path path after the base URL, e.g. "/accounts/ID/images/v1"
:query map of query params (optional; URL-encoded)
:headers map of extra headers (optional)
:json Clojure data to send as a JSON body (optional)
:multipart vector of form parts to send as multipart/form-data (optional)
:body raw byte[] body (optional; ignored if :json/:multipart given)
Returns `{:status int :headers {lower-name [vals]} :body <string>}` for any
completed exchange (including 4xx/5xx) — the body is decoded as a UTF-8 string
(Cloudflare answers JSON even on errors). Network failures throw IOException.(send-streaming client req)Like send-request, but :body in the result is an InputStream — for
downloading a large blob without buffering it. The caller must close (or fully
consume) :body.
Like `send-request`, but `:body` in the result is an InputStream — for downloading a large blob without buffering it. The caller must close (or fully consume) `:body`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |