Cloudflare Workers: list, deploy (single ES module), fetch, and delete scripts, and manage zone routes. Deploying replaces the script and creates a new version and deployment in one step. For multi-module bundles, static assets, or secrets, use wrangler deploy.

Context Vars

Optional
  • cloudflare.token
  • cloudflare.account.id

Values

DEFAULT_COMPATIBILITY_DATE

DEFAULT_COMPATIBILITY_DATE: Str "2025-09-01"

Functions

create-route

fn (zone-id: Str, pattern: Str, script: Str): Map
fn (zone-id: Str, pattern: Str, script: Str, opts: Map): Map

POST /zones/{zone_id}/workers/routes - Route pattern (e.g. "example.com/api/*") to the Worker script. Returns {id, pattern, script}.

Example

route ::cloudflare::workers/create-route("023e105f4ecef8ad9ca31a8372d0c353", "example.com/api/*", "hello")
route.id

delete-route

fn (zone-id: Str, route-id: Str): Any
fn (zone-id: Str, route-id: Str, opts: Map): Any

DELETE /zones/{zone_id}/workers/routes/{route_id} - Remove a route.

Example

::cloudflare::workers/delete-route("023e105f4ecef8ad9ca31a8372d0c353", "9a7806061c88ada191ed06f989cc3dac")

delete-script

fn (name: Str): Any
fn (name: Str, force: Bool): Any
fn (name: Str, opts: Map): Any
fn (name: Str, force: Bool, opts: Map): Any

DELETE .../workers/scripts/{name} - Delete a script. The 2-arity form with force: true also deletes it when other Workers bind to it.

Example

::cloudflare::workers/delete-script("hello")

// Also when other Workers bind to it
::cloudflare::workers/delete-script("hello", true)

deploy-module

fn (name: Str, code: Str): Map
fn (name: Str, code: Str, options: Map): Map
fn (name: Str, code: Str, options: Map, opts: Map): Map

PUT /accounts/{account_id}/workers/scripts/{name} - Upload code as a single ES module Worker (export default { fetch(request, env) {…} }) and deploy it. options as in script-metadata, plus main_module (the part name, default "worker.js"). Returns the script record. The Worker still needs a route, custom domain, or workers.dev subdomain to receive traffic.

Example

::cloudflare::workers/deploy-module("hello", "export default { fetch() { return new Response('hi') } }", {
  bindings: [{type: "plain_text", name: "GREETING", text: "hi"}]
})

deploy-parts

fn (main-module: Str, code: Str, options: Map): Vec

The multipart parts for a module upload: the JSON metadata part and the module itself as application/javascript+module. Exposed for testing.

Example

map(::cloudflare::workers/deploy-parts("worker.js", "export default {}", {}), %.name)  // ["metadata", "worker.js"]

get-script-settings

fn (name: Str): Map
fn (name: Str, opts: Map): Map

GET .../workers/scripts/{name}/settings - A script's bindings, compatibility date and flags, and observability settings.

Example

settings ::cloudflare::workers/get-script-settings("hello")
settings.compatibility_date

list-routes

fn (zone-id: Str): Vec
fn (zone-id: Str, opts: Map): Vec

GET /zones/{zone_id}/workers/routes - A zone's Worker routes: [{id, pattern, script}].

Example

routes ::cloudflare::workers/list-routes("023e105f4ecef8ad9ca31a8372d0c353")
map(routes, %.pattern)

list-scripts

fn (): Vec
fn (opts: Map): Vec

GET /accounts/{account_id}/workers/scripts - Every Worker script in the account (id is the script name). Not paginated.

Example

map(::cloudflare::workers/list-scripts(), %.id)

script-metadata

fn (main-module: Str, options: Map): Map

The metadata part for a module upload. options may set compatibility_date, compatibility_flags, bindings ([{type: "plain_text", name, text}, {type: "kv_namespace", name, namespace_id}, …]), keep_bindings, observability, and tags; unset fields are omitted. Exposed for testing.

Example

::cloudflare::workers/script-metadata("worker.js", {compatibility_date: "2026-01-01", tags: ["prod"]})
// {main_module: "worker.js", compatibility_date: "2026-01-01", tags: ["prod"]}