Skip to content

Commit c9458a0

Browse files
markjmillerkorinneirvinebroque1000hz
authored
docs: update all content to reflect new Workers API (#23774)
* docs: update all content to reflect new Workers API * Update with newest workers examples * updates changelog * updates title * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Cina Saffary <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Cina Saffary <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Cina Saffary <[email protected]> * Update src/content/changelog/workers/2025-09-03-new-workers-api.mdx Co-authored-by: Brendan Irvine-Broque <[email protected]> * Apply suggestions from code review Co-authored-by: Brendan Irvine-Broque <[email protected]> * updates diagrams * updates text for more clarity * cleans up text * Update src/content/docs/workers/platform/infrastructure-as-code.mdx Co-authored-by: Cina Saffary <[email protected]> * Update src/content/docs/workers/platform/infrastructure-as-code.mdx Co-authored-by: Cina Saffary <[email protected]> * adds back in python workers content --------- Co-authored-by: korinne <[email protected]> Co-authored-by: Brendan Irvine-Broque <[email protected]> Co-authored-by: Cina Saffary <[email protected]>
1 parent 2e4fdfa commit c9458a0

File tree

7 files changed

+542
-287
lines changed

7 files changed

+542
-287
lines changed
727 KB
Loading
1.29 MB
Loading
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
---
2+
title: A new, simpler REST API for Cloudflare Workers (Beta)
3+
description: Simpler Workers API, SDK methods, and Terraform resources for directly managing Workers, Versions, and Deployments
4+
date: 2025-09-04
5+
---
6+
You can now manage [**Workers**](/api/resources/workers/subresources/beta/subresources/workers/methods/create/), [**Versions**](/api/resources/workers/subresources/beta/subresources/workers/models/worker/#(schema)), and [**Deployments**](/api/resources/workers/subresources/scripts/subresources/content/methods/update/) as separate resources with a new, resource-oriented API (Beta).
7+
8+
This new API is supported in the [Cloudflare Terraform provider](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs) and the [Cloudflare Typescript SDK](https://github.com/cloudflare/cloudflare-typescript), allowing platform teams to manage a Worker's infrastructure in Terraform, while development teams handle code deployments from a separate repository or workflow. We also designed this API with AI agents in mind, as a clear, predictable structure is essential for them to reliably build, test, and deploy applications.
9+
10+
### Try it out
11+
- [**New beta API endpoints**](/api/resources/workers/subresources/beta/)
12+
- [**Cloudflare TypeScript SDK v5.0.0**](https://github.com/cloudflare/cloudflare-typescript)
13+
- [**Cloudflare Go SDK v6.0.0**](https://github.com/cloudflare/cloudflare-go)
14+
- [**Terraform provider v5.9.0**](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs): [`cloudflare_worker`](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/worker) , [`cloudflare_worker_version`](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/worker_version), and [`cloudflare_workers_deployments`](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/workers_deployment) resources.
15+
- See full examples in our [Infrastructure as Code (IaC) guide](/workers/platform/infrastructure-as-code)
16+
17+
18+
## Before: Eight+ endpoints with mixed responsibilities
19+
![**Before**](~/assets/images/workers/platform/api-before.png)
20+
21+
22+
The existing API was originally designed for simple, one-shot script uploads:
23+
24+
```sh
25+
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/scripts/$SCRIPT_NAME" \
26+
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
27+
-H "X-Auth-Key: $CLOUDFLARE_API_KEY" \
28+
-H "Content-Type: multipart/form-data" \
29+
-F 'metadata={
30+
"main_module": "worker.js",
31+
"compatibility_date": "$today$"
32+
}' \
33+
-F "[email protected];type=application/javascript+module"
34+
35+
```
36+
37+
This API worked for creating a basic Worker, uploading all of its code, and deploying it immediately — but came with challenges:
38+
39+
- **A Worker couldn't exist without code**: To create a Worker, you had to upload its code in the same API request. This meant platform teams couldn't provision Workers with the proper settings, and then hand them off to development teams to deploy the actual code.
40+
41+
- **Several endpoints implicitly created deployments**: Simple updates like adding a secret or changing a script's content would implicitly create a new version and immediately deploy it.
42+
43+
- **Updating a setting was confusing**: Configuration was scattered across eight endpoints with overlapping responsibilities. This ambiguity made it difficult for human developers (and even more so for AI agents) to reliably update a Worker via API.
44+
45+
- **Scripts used names as primary identifiers**: This meant simple renames could turn into a risky migration, requiring you to create a brand new Worker and update every reference. If you were using Terraform, this could inadvertently destroy your Worker altogether.
46+
47+
## After: Three resources with clear boundaries
48+
![**After**](~/assets/images/workers/platform/api-after.png)
49+
The new API introduces cleaner resource management with three core resources: [**Worker**](/api/resources/workers/subresources/beta/subresources/workers/methods/create/), [**Versions**](/api/resources/workers/subresources/beta/subresources/workers/models/worker/#(schema)), and [**Deployment**](/api/resources/workers/subresources/scripts/subresources/content/methods/update/).
50+
51+
All endpoints now use simple JSON payloads, with script content embedded as `base64`-encoded strings -- a more consistent and reliable approach than the previous `multipart/form-data` format.
52+
- **Worker**: The parent resource representing your application. It has a stable UUID and holds persistent settings like `name`, `tags`, and `logpush`. You can now create a Worker to establish its identity and settings **before** any code is uploaded.
53+
54+
- **Version**: An immutable snapshot of your code and its specific configuration, like bindings and `compatibility_date`. Creating a new version is a safe action that doesn't affect live traffic.
55+
56+
- **Deployment**: An explicit action that directs traffic to a specific version.
57+
58+
:::note
59+
[Workers](/api/resources/workers/subresources/beta/subresources/workers/) and [Versions](/api/resources/workers/subresources/beta/subresources/workers/subresources/versions/) use the new `/workers/` beta endpoints, while [Deployments](/api/resources/workers/subresources/scripts/subresources/deployments/) remain on the existing `/scripts/` endpoint. Pair the new endpoints with the existing Deployment API for a complete workflow.
60+
:::
61+
62+
## Why this matters
63+
64+
### You can now create Workers before uploading code
65+
66+
Workers are now standalone resources that can be created and configured without any code. Platform teams can provision Workers with the right settings, then hand them off to development teams for implementation.
67+
68+
#### Example: Typescript SDK
69+
```ts
70+
// Step 1: Platform team creates the Worker resource (no code needed)
71+
const worker = await client.workers.beta.workers.create({
72+
name: "payment-service",
73+
account_id: "...",
74+
observability: {
75+
enabled: true,
76+
},
77+
});
78+
79+
// Step 2: Development team adds code and creates a version later
80+
const version = await client.workers.beta.workers.versions.create(worker.id, {
81+
account_id: "...",
82+
main_module: "worker.js",
83+
compatibility_date: "$today",
84+
bindings: [ /*...*/ ],
85+
modules: [
86+
{
87+
name: "worker.js",
88+
content_type: "application/javascript+module",
89+
content_base64: Buffer.from(scriptContent).toString("base64"),
90+
},
91+
],
92+
});
93+
94+
// Step 3: Deploy explicitly when ready
95+
const deployment = await client.workers.scripts.deployments.create(worker.name, {
96+
account_id: "...",
97+
strategy: "percentage",
98+
versions: [
99+
{
100+
percentage: 100,
101+
version_id: version.id,
102+
},
103+
],
104+
});
105+
````
106+
#### Example: Terraform
107+
If you use Terraform, you can now declare the Worker in your Terraform configuration and manage configuration outside of Terraform in your Worker's [`wrangler.jsonc` file](/workers/wrangler/configuration/) and deploy code changes using [Wrangler](/workers/wrangler/).
108+
109+
```tf
110+
resource "cloudflare_worker" "my_worker" {
111+
account_id = "..."
112+
name = "my-important-service"
113+
}
114+
# Manage Versions and Deployments here or outside of Terraform
115+
# resource "cloudflare_worker_version" "my_worker_version" {}
116+
# resource "cloudflare_workers_deployment" "my_worker_deployment" {}
117+
```
118+
119+
### Deployments are always explicit, never implicit
120+
121+
Creating a version and deploying it are now always explicit, separate actions - never implicit side effects. To update version-specific settings (like bindings), you create a new version with those changes. The existing deployed version remains unchanged until you explicitly deploy the new one.
122+
123+
```sh
124+
# Step 1: Create a new version with updated settings (doesn't affect live traffic)
125+
POST /workers/workers/{id}/versions
126+
{
127+
"compatibility_date": "$today",
128+
"bindings": [
129+
{
130+
"name": "MY_NEW_ENV_VAR",
131+
"text": "new_value",
132+
"type": "plain_text"
133+
}
134+
],
135+
"modules": [...]
136+
}
137+
138+
# Step 2: Explicitly deploy when ready (now affects live traffic)
139+
POST /workers/scripts/{script_name}/deployments
140+
{
141+
"strategy": "percentage",
142+
"versions": [
143+
{
144+
"percentage": 100,
145+
"version_id": "new_version_id"
146+
}
147+
]
148+
}
149+
```
150+
151+
### Settings are clearly organized by scope
152+
Configuration is now logically divided: [**Worker settings**](/api/resources/workers/subresources/beta/subresources/workers/) (like `name` and `tags`) persist across all versions, while [**Version settings**](/api/resources/workers/subresources/beta/subresources/workers/subresources/versions/) (like `bindings` and `compatibility_date`) are specific to each code snapshot.
153+
154+
```sh
155+
# Worker settings (the parent resource)
156+
PUT /workers/workers/{id}
157+
{
158+
"name": "payment-service",
159+
"tags": ["production"],
160+
"logpush": true,
161+
}
162+
```
163+
164+
```sh
165+
# Version settings (the "code")
166+
POST /workers/workers/{id}/versions
167+
{
168+
"compatibility_date": "$today",
169+
"bindings": [...],
170+
"modules": [...]
171+
}
172+
```
173+
174+
### `/workers` API endpoints now support UUIDs (in addition to names)
175+
176+
The `/workers/workers/` path now supports addressing a Worker by both its immutable UUID and its mutable name.
177+
178+
```sh
179+
# Both work for the same Worker
180+
GET /workers/workers/29494978e03748669e8effb243cf2515 # UUID (stable for automation)
181+
GET /workers/workers/payment-service # Name (convenient for humans)
182+
```
183+
This dual approach means:
184+
- Developers can use readable names for debugging.
185+
- Automation can rely on stable UUIDs to prevent errors when Workers are renamed.
186+
- Terraform can rename Workers without destroying and recreating them.
187+
188+
189+
## Learn more
190+
- [Infrastructure as Code (IaC) guide](/workers/platform/infrastructure-as-code)
191+
- [API documentation](/api/resources/workers/subresources/beta/)
192+
- [Versions and Deployments overview](/workers/configuration/versions-and-deployments/)
193+
194+
## Technical notes
195+
196+
- The pre-existing Workers REST API remains fully supported. Once the new API exits beta, we'll provide a migration timeline with ample notice and comprehensive migration guides.
197+
- Existing Terraform resources and SDK methods will continue to be fully supported through the current major version.
198+
- While the Deployments API currently remains on the `/scripts/` endpoint, we plan to introduce a new Deployments endpoint under `/workers/` to match the new API structure.

src/content/docs/workers/configuration/multipart-upload-metadata.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ title: Multipart upload metadata
55

66
import { Type, MetaInfo } from "~/components";
77

8+
:::note
9+
10+
There is a new API for uploading Workers. Refer to [these docs](/workers/platform/infrastructure-as-code#cloudflare-rest-api) for more information.
11+
:::
12+
813
If you're using the [Workers Script Upload API](/api/resources/workers/subresources/scripts/methods/update/) or [Version Upload API](/api/resources/workers/subresources/scripts/subresources/versions/methods/create/) directly, `multipart/form-data` uploads require you to specify a `metadata` part. This metadata defines the Worker's configuration in JSON format, analogue to the [wrangler.toml file](/workers/wrangler/configuration/).
914

1015
## Sample `metadata`

src/content/docs/workers/configuration/versions-and-deployments/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ When using [Wrangler](/workers/wrangler/), changes made to a Worker's triggers [
6969
New versions are not created when you make changes to [resources connected to your Worker](/workers/runtime-apis/bindings/). For example, if two Workers (Worker A and Worker B) are connected via a [service binding](/workers/runtime-apis/bindings/service-bindings/), changing the code of Worker B will not create a new version of Worker A. Changing the code of Worker B will only create a new version of Worker B. Changes to the service binding (such as, deleting the binding or updating the [environment](/workers/wrangler/environments/) it points to) on Worker A will also not create a new version of Worker B.
7070
:::
7171

72+
#### Directly manage Versions and Deployments
73+
74+
See examples of creating a Worker, Versions, and Deployments directly with the API, library SDKs, and Terraform in [Infrastructure as Code](/workers/platform/infrastructure-as-code/).
75+
7276
### View versions and deployments
7377

7478
#### Via Wrangler

0 commit comments

Comments
 (0)