You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/changelog/workers/2025-09-02-new-workers-api.mdx
+25-19Lines changed: 25 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,28 @@
1
1
---
2
2
title: Simpler Workers API that lets you directly manage Workers, Versions, and Deployments
3
3
description: Simpler Workers API, SDK methods, and Terraform resources for directly managing Workers, Versions, and Deployments
4
-
date: 2025-08-11
4
+
date: 2025-09-02
5
5
---
6
6
7
7
The current Workers script upload API is convenient for a one-shot Workers deploy. However, it unavoidably creates [Versions and Deployments](/workers/configuration/versions-and-deployments/), and sometimes you don't want that to happen. Sometimes, you want more (and simpler!) control over how and when these are created.
8
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 way to upload modules, fewer total endpoints, and clearer [API docs](/api/resources/workers/). Check out [Infrastructure as Code (IaC)](/workers/platform/infrastructure-as-code) for detailed examples.
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, 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 way to upload modules, fewer total endpoints, and clearer [API docs](/api/resources/workers/). Check out [Infrastructure as Code (IaC)](/workers/platform/infrastructure-as-code) for detailed examples.
10
10
11
11
## cloudflare-typescript example
12
12
13
13
```javascript
14
14
constscriptContent=`
15
15
export default {
16
16
async fetch(request, env, ctx) {
17
-
return new Response(env.MESSAGE, { status: 200 });
17
+
return new Response("Hello, world!", { status: 200 });
18
18
}
19
19
};
20
20
`;
21
21
22
22
/**
23
23
* Create a Worker and set non-versioned settings like observability
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—in a different repo—while maintaining presence in your Terraform plan.
68
+
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 deploywhile maintaining presence in your Terraform plan.
We wanted to make things easier, so we simplified these 8 APIs...
84
-
- /workers/scripts/:script_name
85
-
- /workers/scripts/:script_name/content
86
-
- /workers/scripts/:script_name/script-settings
87
-
- /workers/scripts/:script_name/settings
88
-
- /workers/scripts/:script_name/subdomain
89
-
- /workers/scripts/:script_name/secrets
90
-
- /workers/scripts/:script_name/versions
91
-
- /workers/scripts/:script_name/deployments
84
+
-`/workers/scripts/:script_name`
85
+
-`/workers/scripts/:script_name/content`
86
+
-`/workers/scripts/:script_name/script-settings`
87
+
-`/workers/scripts/:script_name/settings`
88
+
-`/workers/scripts/:script_name/subdomain`
89
+
-`/workers/scripts/:script_name/secrets`
90
+
-`/workers/scripts/:script_name/versions`
91
+
-`/workers/scripts/:script_name/deployments`
92
92
93
93
Into just three!
94
-
- /workers/workers/:worker_id
95
-
- /workers/workers/:worker_id/versions
96
-
- /workers/scripts/:script_name/deployments
94
+
-`/workers/workers/:worker_id`
95
+
-`/workers/workers/:worker_id/versions`
96
+
-`/workers/scripts/:script_name/deployments`
97
97
98
-
It's not just fewer endpoints... can you guess which of the old APIs created a new Version and Deployment and which didn't? That's no longer a mystery. POST `/versions` creates a Version and POST `/deployments` creates a Deployment.
98
+
It's not just fewer endpoints... can you guess which of the old APIs created a new Version and Deployment and which didn't? That's no longer a mystery. `/versions` creates Versions and `/deployments` creates Deployments.
99
99
100
-
For now, the new APIs are in beta and the old ones will remain operational. In the future, we plan to mark the old APIs as deprecated in our OpenAPI docs, and remove the old Terraform resources and SDK methods in future major versions.
100
+
For now, the new APIs are in **beta** and the old ones will remain operational. In the future, we plan to mark the old APIs as deprecated in our OpenAPI docs, and remove the old Terraform resources and SDK methods in future major versions.
101
+
102
+
:::note
103
+
-`/workers/workers/` is deliberate and not a typo. This is so we can support both Worker ID and aliased name: `/workers/workers/7f694d3716bc4a63ad285159ff1fa375` and `/workers/workers/my-worker` both work.
104
+
- The deployments endpoint is unchanged because there's no change to the functionality at this time. It will be changed in the future to be consistent with the rest of the APIs.
105
+
- We won't deprecate the ability to one-shot create a Worker and deployment without a better replacement.
Copy file name to clipboardExpand all lines: src/content/docs/workers/platform/infrastructure-as-code.mdx
+43-3Lines changed: 43 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ import { Icon } from "astro-icon/components";
10
10
11
11
While [Wrangler](/workers/wrangler/configuration) makes it easy to upload and manage Workers, there are times when you need a more programmatic approach. This could involve using Infrastructure as Code (IaC) tools or interacting directly with the [Workers API](/api/resources/workers/). Examples include build and deploy scripts, CI/CD pipelines, custom developer tools, and automated testing.
12
12
13
-
To make this easier, Cloudflare provides SDK libraries for popular languages, including [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) and [cloudflare-python](https://github.com/cloudflare/cloudflare-python). For IaC, you can use tools like HashiCorp's Terraform and the [Cloudflare Terraform Provider](/terraform) manage Workers resources.
13
+
To make this easier, Cloudflare provides SDK libraries for popular languages such as [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) and [cloudflare-python](https://github.com/cloudflare/cloudflare-python). For IaC, you can use tools like HashiCorp's Terraform and the [Cloudflare Terraform Provider](/terraform) to manage Workers resources.
14
14
15
15
Below are examples of deploying a Worker using different tools and languages, along with important considerations for managing Workers with IaC.
16
16
@@ -26,7 +26,7 @@ Generally, you'd run this bundling step before applying your Terraform plan or u
26
26
wrangler deploy --dry-run --outdir build
27
27
```
28
28
29
-
When using Wrangler for building but another method for uploading, make sure to copy all of your config from `wrangler.json` into your Terraform config, API request, or other. This is especially important with `compatibility_date` or flags your script relies on.
29
+
When using Wrangler for building and a different method for uploading, make sure to copy all of your config from `wrangler.json` into your Terraform config or API request. This is especially important with `compatibility_date` or flags your script relies on.
Notice how you don't have to manage all of these resources in Terraform. For example, you could just the `cloudflare_worker` resource and seamlessly use Wrangler or your own deployment tools for Versions or Deployments.
75
+
71
76
## Cloudflare API Libraries
72
77
73
78
This example uses the [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) SDK which provides convenient access to the Cloudflare REST API from server-side JavaScript or TypeScript.
74
79
75
80
<GitHubCode
76
81
repo="cloudflare/cloudflare-typescript"
77
82
file="examples/workers/script-upload.ts"
78
-
commit="a7baf4fed47910228880800d5887a5d438baa6ad"
83
+
commit="cb55a45d615425f6aaf9ee8a237d2c5424bf30b7"
79
84
lang="ts"
80
85
useTypeScriptExample={true}
81
86
/>
@@ -346,3 +351,38 @@ EOF
346
351
347
352
</TabItem>
348
353
</Tabs>
354
+
355
+
## Considerations with Durable Objects
356
+
357
+
[Durable Object](/durable-objects/) migrations are applied with deployments. This means you can't bind to a durable object in a Version if a deployment doesn't exist i.e. migrations haven't been applied. For example, running this in Terraform will fail the first time the plan is applied:
To make this succeed, you first have to comment out the `durable_object` binding block, apply the plan, uncomment it, comment out the `migrations` block, then apply again. This time the plan will succeed. This also applies to the API or SDKs. This is an example where it makes sense to just manage the `cloudflare_worker` and/or `cloudflare_workers_deployment` resources while using Wrangler for build and Version management.
Copy file name to clipboardExpand all lines: src/content/docs/workers/static-assets/direct-upload.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -215,12 +215,12 @@ Optionally, an assets binding can be provided if you wish to fetch and serve ass
215
215
216
216
## Programmatic Example
217
217
218
-
TODO update this with the prod commit
218
+
This example is from [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript/blob/main/examples/workers/script-with-assets-upload.ts).
0 commit comments