Skip to content

Commit 5a12688

Browse files
committed
updates changelog
1 parent ccd5040 commit 5a12688

File tree

3 files changed

+150
-106
lines changed

3 files changed

+150
-106
lines changed
273 KB
Loading

src/content/changelog/workers/2025-09-02-new-workers-api.mdx

Lines changed: 0 additions & 106 deletions
This file was deleted.
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: Simpler Workers API that lets you directly manage Workers, Versions, and Deployments
3+
description: Simpler Workers API, SDK methods, and Terraform resources for directly managing Workers, Versions, and Deployments
4+
date: 2025-09-03
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). This new API is supported in our [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 agents in mind, as a clear, predictable structure is essential for them to reliably build, test, and deploy applications.
7+
8+
### Try it out
9+
- [**New beta API endpoints**](/api/resources/workers/subresources/beta/)
10+
- [**Cloudflare TypeScript SDK v4.6.0**](https://github.com/cloudflare/cloudflare-typescript)
11+
- [**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.
12+
13+
![**Before and after**](~/assets/images/workers/platform/endpoints.png)
14+
15+
## Before: Eight endpoints with mixed responsibilities
16+
The existing API was originally designed for simple, one-shot script uploads.
17+
18+
```sh
19+
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/scripts/$SCRIPT_NAME" \
20+
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
21+
-H "X-Auth-Key: $CLOUDFLARE_API_KEY" \
22+
-H "Content-Type: multipart/form-data" \
23+
-F 'metadata={
24+
"main_module": "worker.js",
25+
"compatibility_date": "$today$"
26+
}' \
27+
-F "[email protected];type=application/javascript+module"
28+
29+
```
30+
31+
This structure works great for conveniently creating a Worker, uploading all of its code, and deploying it immediately -- but came with its own problems, such as:
32+
33+
- **A Worker couldn't exist without code**: To create a Worker, you had to upload its code in the same operation. While this doesn't pose a problem for smaller teams, this prevented platform teams in larger organizations from provisioning Workers with the proper settings, and then handing them off to development teams to deploy the actual code.
34+
35+
- **Updating settings was confusing and fragmented**: With the existing API, configuration is scattered across eight different endpoints with overlapping responsibilities. This made it challenging for human developers (and even more difficult for automated agents) to reliably update a Worker's settings. You had to guess between [`/settings`](/api/resources/workers/subresources/scripts/subresources/schedules/methods/update/) and [`/script-settings`](/api/resources/workers/subresources/scripts/subresources/settings/methods/edit/), with not a lot of clarity about which endpoint updated all versions or a specific version of a Worker.
36+
37+
- **Scripts used names as primary identifiers**: The existing API uses the Worker script name as the primary identifier for a Worker, which meant that if you wanted to rename a Worker via API, you needed to deploy an entirely new script and update every reference across your infrastructure. If you were using Terraform, renaming a Worker could easily result in destroying the Worker altogether.
38+
39+
## After: Three resources with clear boundaries
40+
We have consolidated the API around three core resources with distinct boundaries: [**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/). All endpoints now use clean JSON payloads, with script content embedded as `base64`-encoded string, a simpler and more reliable approach than the previous `multipart/form-data` format.
41+
- **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.
42+
43+
- **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.
44+
45+
- **Deployment**: An explicit action that directs traffic to a specific version.
46+
47+
## Why this matters
48+
49+
### Separation of concerns
50+
51+
The new API enables proper separation of concerns between infrastructure and application teams.
52+
53+
#### Example: Typescript SDK
54+
```ts
55+
// Step 1: Platform team creates the Worker resource (no code needed)
56+
const worker = await client.workers.beta.workers.create({
57+
"payment-service",
58+
account_id: "...",
59+
observability: {
60+
enabled: true,
61+
},
62+
});
63+
64+
// Step 2: Development team adds code and creates a version later
65+
const version = await client.workers.beta.workers.versions.create(worker.id, {
66+
account_id: "...",
67+
main_module: "payment-service-script",
68+
compatibility_date: "$today",
69+
bindings: [ /*...*/ ],
70+
modules: [
71+
{
72+
name: "payment-service",
73+
content_type: "application/javascript+module",
74+
content_base64: Buffer.from(scriptContent).toString("base64"),
75+
},
76+
],
77+
});
78+
79+
// Step 3: Deploy explicitly when ready
80+
const deployment = await client.workers.scripts.deployments.create(worker.name, {
81+
account_id: "...",
82+
strategy: "percentage",
83+
versions: [
84+
{
85+
percentage: 100,
86+
version_id: version.id,
87+
},
88+
],
89+
});
90+
````
91+
#### Example: Terraform
92+
For those using Terraform, you can now track the Worker's existence without needing to also manage its configuration and deployments. This gives you flexibility to use Wrangler for building and deploying your code, while still using Terraform as your source of truth for your Worker's infrastructure.
93+
94+
```tf
95+
resource "cloudflare_worker" "my_worker" {
96+
account_id = "..."
97+
name = "my-important-service"
98+
}
99+
# Manage Versions and Deployments here or outside of Terraform
100+
# resource "cloudflare_worker_version" "my_worker_version" {}
101+
# resource "cloudflare_workers_deployment" "my_worker_deployment" {}
102+
```
103+
104+
### Predictable settings
105+
Configuration now has an obvious home. Worker settings persist across all versions of the Worker, and Version settings are specific to a code snapshot.
106+
107+
```sh
108+
# Worker settings (the parent resource)
109+
PUT /workers/workers/{id}
110+
{
111+
"name": "payment-service",
112+
"tags": ["production"],
113+
"logpush": true,
114+
}
115+
```
116+
117+
```sh
118+
# Version settings (the "code")
119+
POST /workers/workers/{id}/versions
120+
{
121+
"compatibility_date": "$today",
122+
"bindings": [...],
123+
"modules": [...]
124+
}
125+
```
126+
127+
### Dual addressing for stability and convenience
128+
129+
The `/workers/workers/` path now supports addressing a Worker by both its immutable UUID and its mutable name.
130+
131+
```sh
132+
# Both work for the same Worker
133+
GET /workers/workers/29494978e03748669e8effb243cf2515 # UUID (stable for automation)
134+
GET /workers/workers/payment-service # Name (convenient for humans)
135+
```
136+
This dual approach means:
137+
- Developers can use readable names for debugging.
138+
- Automation can rely on stable UUIDs to prevent errors.
139+
- Terraform can rename Workers without destroying and recreating them.
140+
141+
142+
## Learn more
143+
- [Infrastructure as Code (IaC) guide](/workers/platform/infrastructure-as-code)
144+
- [API documentation](/api/resources/workers/subresources/beta/)
145+
- [Versions and Deployments overview](/workers/configuration/versions-and-deployments/)
146+
147+
## Technical notes
148+
149+
- Current APIs remain operational during beta, and any deprecation notice will come with a defined support period.
150+
- Legacy Terraform resources and SDK methods will be supported until the next major version.

0 commit comments

Comments
 (0)