Skip to content

Commit 4254674

Browse files
committed
docs: update all content to reflect new Workers API
1 parent 698edbd commit 4254674

File tree

6 files changed

+351
-319
lines changed

6 files changed

+351
-319
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: New Workers API that allows you to explicitly manage Workers, Versions, and Deployments
3+
description: New Workers API, SDK methods, and Terraform resources for explicitly managing Workers, Versions, and Deployments
4+
date: 2025-08-11
5+
---
6+
7+
The current Workers script upload API and its corresponding SDK methods (i.e. [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) and [cloudflare-python](https://github.com/cloudflare/cloudflare-python)) and Terraform resource ([cloudflare_workers_script](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/workers_script)) are convenient for a one-shot Workers deployment, but sometimes that does too much. This API unavoidably creates a Version and a Deployment (see [Versions and Deployments](/workers/configuration/versions-and-deployments/)). However, these are separate resources you can individually manage, and sometimes you want more control over how and when these are created.
8+
9+
In [Cloudflare Terraform Provider](https://registry.terraform.io/providers/cloudflare/cloudflare/5.9.0/docs) 5.9.0 and [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) 4.6.0 (TODO double check these versions), we're introducing a clean, separated API that makes Workers, Versions, and Deployments individual "capital R" resources with clear concerns. It's now possible to create a Worker entity--and reference it elsewhere--before uploading code, bindings, or making it routable from the internet. You'll also enjoy a more ergonomic modules upload interface vs the old multipart/form-data API.
10+
11+
This example uses the [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) SDK library.
12+
13+
```javascript
14+
const scriptContent = `
15+
export default {
16+
async fetch(request, env, ctx) {
17+
return new Response(env.MESSAGE, { status: 200 });
18+
}
19+
};
20+
`;
21+
22+
/**
23+
* Create a Worker and set non-versioned settings like observability
24+
*/
25+
const worker = await client.workers.create("my-worker", {
26+
account_id: "...",
27+
observability: {
28+
enabled: true,
29+
},
30+
});
31+
32+
/**
33+
* Create the first version of the Worker
34+
* This is where code and bindings are defined and can be different between versions
35+
*/
36+
const version = await client.workers.versions.create(worker.id, {
37+
account_id: "...",
38+
main_module: "my-worker-script",
39+
compatibility_date: $today,
40+
bindings: [ /*...*/ ],
41+
modules: [
42+
{
43+
name: "my-worker-script",
44+
content_type: "application/javascript+module",
45+
content_base64: Buffer.from(scriptContent).toString("base64"),
46+
},
47+
],
48+
});
49+
50+
/**
51+
* Create a deployment and point all traffic to the version we created
52+
*/
53+
const deployment = await client.workers.scripts.deployments.create(worker.name, {
54+
account_id: "...",
55+
strategy: "percentage",
56+
versions: [
57+
{
58+
percentage: 100,
59+
version_id: version.id,
60+
},
61+
],
62+
});
63+
```
64+
65+
In Terraform, you now have the option to just manage the Worker entity. You don't need to manage code, config, or deployments in your plan. This gives you flexibility to use Wrangler for build and deploy while maintaining IaC presence.
66+
67+
```tf
68+
resource "cloudflare_worker" "my_worker" {
69+
account_id = "..."
70+
name = "my-important-service"
71+
}
72+
73+
# Manage these here or outside of Terraform
74+
# resource "cloudflare_workers_version" "my_worker_version" {}
75+
# resource "cloudflare_workers_deployment" "my_worker_deployment" {}
76+
```
77+
78+
Check out [Infrastructure as Code (IaC)](/workers/platform/infrastructure-as-code) for more details and examples.

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. See [here](/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

src/content/docs/workers/observability/logs/logpush.mdx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,6 @@ route = { pattern = "example.org/*", zone_name = "example.org" }
9393

9494
</WranglerConfig>
9595

96-
Configure via multipart script upload API:
97-
98-
```bash
99-
curl --request PUT \
100-
"https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/scripts/{script_name}" \
101-
--header "Authorization: Bearer <API_TOKEN>" \
102-
--form 'metadata={"main_module": "my-worker.js", "logpush": true}' \
103-
--form '"my-worker.js"=@./my-worker.js;type=application/javascript+module'
104-
```
105-
10696
## Limits
10797

10898
The `logs` and `exceptions` fields have a combined limit of 16,384 characters before fields will start being truncated. Characters are counted in the order of all `exception.name`s, `exception.message`s, and then `log.message`s.

0 commit comments

Comments
 (0)