Skip to main content

Module cf

Module cf 

Source
Expand description

Access Cloudflare Worker bindings and request context from inside #[server] functions.

§Binding shortcuts

  • cf::d1() — D1 database (combines env + binding lookup + error conversion)
  • cf::kv() — Workers KV namespace
  • cf::r2() — R2 bucket
  • cf::durable_object() — Durable Object namespace
  • [cf::queue()] — Queue producer (requires queue feature)

§Raw access

  • cf::env() — the full Worker Env (for bindings without a shorthand)
  • cf::req() — the raw worker::Request (headers, IP)

§Incoming cookies

§Outgoing cookies

Outgoing cookies are queued in thread-local storage and applied to the response by handle — no &mut Response needed inside server functions.

Structs§

CookieBuilder
Builder for cookies with custom options.

Enums§

SameSite
SameSite attribute for cookies.

Functions§

clear_cookie
Queue a cookie-clearing header on the outgoing response (Max-Age=0).
cookie
Read a named cookie from the incoming request’s Cookie header.
cookies
Read all cookies from the incoming request’s Cookie header.
d1
Access a D1 database binding by name.
durable_object
Access a Durable Object namespace binding by name.
env
Access the Cloudflare Worker Env from inside any #[server] function.
kv
Access a Workers KV namespace binding by name.
r2
Access an R2 bucket binding by name.
req
Access the raw Cloudflare Worker worker::Request for the current request.
set_cookie
Queue an HttpOnly auth cookie on the outgoing response.
set_cookie_with
Start building a cookie with custom options.