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}.

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.

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.

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.

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.

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}].

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.

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.

script-suffix

fn (name: Str): Str