Skip to content

Commit 50b9991

Browse files
committed
[Workers] Add getting started guide for API and IaC
1 parent 031f2c8 commit 50b9991

File tree

2 files changed

+224
-135
lines changed

2 files changed

+224
-135
lines changed
Lines changed: 128 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
pcx_content_type: concept
33
title: Multipart upload metadata
4-
54
---
65

76
import { Type, MetaInfo } from "~/components";
@@ -12,18 +11,23 @@ If you're using the [Workers Script Upload API](/api/resources/workers/subresour
1211

1312
```json
1413
{
15-
"main_module": "main.js",
16-
"bindings": [
17-
{
18-
"type": "plain_text",
19-
"name": "MESSAGE",
20-
"text": "Hello, world!"
21-
}
22-
],
23-
"compatibility_date": "2021-09-14"
14+
"main_module": "main.js",
15+
"bindings": [
16+
{
17+
"type": "plain_text",
18+
"name": "MESSAGE",
19+
"text": "Hello, world!"
20+
}
21+
],
22+
"compatibility_date": "2021-09-14"
2423
}
2524
```
2625

26+
:::note
27+
28+
See the [Workers API and IaC](/workers/get-started/api-iac) getting started guide for examples of this.
29+
:::
30+
2731
## Attributes
2832

2933
The following attributes are configurable at the top-level.
@@ -33,41 +37,38 @@ The following attributes are configurable at the top-level.
3337
At a minimum, the `main_module` key is required to upload a Worker.
3438
:::
3539

40+
- `main_module` <Type text="string" /> <MetaInfo text="required" />
3641

42+
- The part name that contains the module entry point of the Worker that will be executed. For example, `main.js`.
3743

38-
* `main_module` <Type text="string" /> <MetaInfo text="required" />
39-
40-
* The part name that contains the module entry point of the Worker that will be executed. For example, `main.js`.
41-
42-
* `assets` <Type text="object" /> <MetaInfo text="optional" />
43-
44-
* [Asset](/workers/static-assets/) configuration for a Worker.
45-
* `config` <Type text="object" /> <MetaInfo text="optional" />
46-
* [html_handling](/workers/static-assets/routing/#1-html_handling) determines the redirects and rewrites of requests for HTML content.
47-
* [not_found_handling](/workers/static-assets/routing/#2-not_found_handling) determines the response when a request does not match a static asset, and there is no Worker script.
48-
* `jwt` field provides a token authorizing assets to be attached to a Worker.
44+
- `assets` <Type text="object" /> <MetaInfo text="optional" />
4945

50-
* `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />
46+
- [Asset](/workers/static-assets/) configuration for a Worker.
47+
- `config` <Type text="object" /> <MetaInfo text="optional" />
48+
- [html_handling](/workers/static-assets/routing/#1-html_handling) determines the redirects and rewrites of requests for HTML content.
49+
- [not_found_handling](/workers/static-assets/routing/#2-not_found_handling) determines the response when a request does not match a static asset, and there is no Worker script.
50+
- `jwt` field provides a token authorizing assets to be attached to a Worker.
5151

52-
* Specifies whether assets should be retained from a previously uploaded Worker version; used in lieu of providing a completion token.
52+
- `keep_assets` <Type text="boolean" /> <MetaInfo text="optional" />
5353

54-
* `bindings` array\[object] optional
54+
- Specifies whether assets should be retained from a previously uploaded Worker version; used in lieu of providing a completion token.
5555

56-
* [Bindings](#bindings) to expose in the Worker.
56+
- `bindings` array\[object] optional
5757

58-
* `placement` <Type text="object" /> <MetaInfo text="optional" />
58+
- [Bindings](#bindings) to expose in the Worker.
5959

60-
* [Smart placement](/workers/configuration/smart-placement/) object for the Worker.
61-
* `mode` field only supports `smart` for automatic placement.
60+
- `placement` <Type text="object" /> <MetaInfo text="optional" />
6261

63-
* `compatibility_date` <Type text="string" /> <MetaInfo text="optional" />
62+
- [Smart placement](/workers/configuration/smart-placement/) object for the Worker.
63+
- `mode` field only supports `smart` for automatic placement.
6464

65-
* [Compatibility Date](/workers/configuration/compatibility-dates/#setting-compatibility-date) indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker. Highly recommended to set a `compatibility_date`, otherwise if on upload via the API, it defaults to the oldest compatibility date before any flags took effect (2021-11-02).
65+
- `compatibility_date` <Type text="string" /> <MetaInfo text="optional" />
6666

67-
* `compatibility_flags` array\[string] optional
67+
- [Compatibility Date](/workers/configuration/compatibility-dates/#setting-compatibility-date) indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker. Highly recommended to set a `compatibility_date`, otherwise if on upload via the API, it defaults to the oldest compatibility date before any flags took effect (2021-11-02).
6868

69-
* [Compatibility Flags](/workers/configuration/compatibility-flags/#setting-compatibility-flags) that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a `compatibility_date`.
69+
- `compatibility_flags` array\[string] optional
7070

71+
- [Compatibility Flags](/workers/configuration/compatibility-flags/#setting-compatibility-flags) that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a `compatibility_date`.
7172

7273
## Additional attributes: [Workers Script Upload API](/api/resources/workers/subresources/scripts/methods/update/)
7374

@@ -78,25 +79,21 @@ For [immediately deployed uploads](/workers/configuration/versions-and-deploymen
7879
These attributes are **not available** for version uploads.
7980
:::
8081

82+
- `migrations` array\[object] optional
8183

84+
- [Durable Objects migrations](/durable-objects/reference/durable-objects-migrations/) to apply.
8285

83-
* `migrations` array\[object] optional
86+
- `logpush` <Type text="boolean" /> <MetaInfo text="optional" />
8487

85-
* [Durable Objects migrations](/durable-objects/reference/durable-objects-migrations/) to apply.
88+
- Whether [Logpush](/cloudflare-for-platforms/cloudflare-for-saas/hostname-analytics/#logpush) is turned on for the Worker.
8689

87-
* `logpush` <Type text="boolean" /> <MetaInfo text="optional" />
90+
- `tail_consumers` array\[object] optional
8891

89-
* Whether [Logpush](/cloudflare-for-platforms/cloudflare-for-saas/hostname-analytics/#logpush) is turned on for the Worker.
90-
91-
* `tail_consumers` array\[object] optional
92-
93-
* [Tail Workers](/workers/observability/logs/tail-workers/) that will consume logs from the attached Worker.
94-
95-
* `tags` array\[string] optional
96-
97-
* List of strings to use as tags for this Worker.
92+
- [Tail Workers](/workers/observability/logs/tail-workers/) that will consume logs from the attached Worker.
9893

94+
- `tags` array\[string] optional
9995

96+
- List of strings to use as tags for this Worker.
10097

10198
## Additional attributes: [Version Upload API](/api/resources/workers/subresources/scripts/subresources/versions/methods/create/)
10299

@@ -107,104 +104,100 @@ For [version uploads](/workers/configuration/versions-and-deployments/#upload-a-
107104
These attributes are **not available** for immediately deployed uploads.
108105
:::
109106

107+
- `annotations` <Type text="object" /> <MetaInfo text="optional" />
110108

111-
112-
* `annotations` <Type text="object" /> <MetaInfo text="optional" />
113-
114-
* Annotations object specific to the Worker version.
115-
* `workers/message` specifies a custom message for the version.
116-
* `workers/tag` specifies a custom identifier for the version.
117-
118-
109+
- Annotations object specific to the Worker version.
110+
- `workers/message` specifies a custom message for the version.
111+
- `workers/tag` specifies a custom identifier for the version.
119112

120113
## Bindings
121114

122115
Workers can interact with resources on the Cloudflare Developer Platform using [bindings](/workers/runtime-apis/bindings/). Refer to the JSON example below that shows how to add bindings in the `metadata` part.
123116

124117
```json
125118
{
126-
"bindings": [
127-
{
128-
"type": "ai",
129-
"name": "<VARIABLE_NAME>"
130-
},
131-
{
132-
"type": "analytics_engine",
133-
"name": "<VARIABLE_NAME>",
134-
"dataset": "<DATASET>"
135-
},
136-
{
137-
"type": "assets",
138-
"name": "<VARIABLE_NAME>"
139-
},
140-
{
141-
"type": "browser_rendering",
142-
"name": "<VARIABLE_NAME>"
143-
},
144-
{
145-
"type": "d1",
146-
"name": "<VARIABLE_NAME>",
147-
"id": "<D1_ID>"
148-
},
149-
{
150-
"type": "durable_object_namespace",
151-
"name": "<VARIABLE_NAME>",
152-
"class_name": "<DO_CLASS_NAME>"
153-
},
154-
{
155-
"type": "hyperdrive",
156-
"name": "<VARIABLE_NAME>",
157-
"id": "<HYPERDRIVE_ID>"
158-
},
159-
{
160-
"type": "kv_namespace",
161-
"name": "<VARIABLE_NAME>",
162-
"namespace_id": "<KV_ID>"
163-
},
164-
{
165-
"type": "mtls_certificate",
166-
"name": "<VARIABLE_NAME>",
167-
"certificate_id": "<MTLS_CERTIFICATE_ID>"
168-
},
169-
{
170-
"type": "plain_text",
171-
"name": "<VARIABLE_NAME>",
172-
"text": "<VARIABLE_VALUE>"
173-
},
174-
{
175-
"type": "queue",
176-
"name": "<VARIABLE_NAME>",
177-
"queue_name": "<QUEUE_NAME>"
178-
},
179-
{
180-
"type": "r2_bucket",
181-
"name": "<VARIABLE_NAME>",
182-
"bucket_name": "<R2_BUCKET_NAME>"
183-
},
184-
{
185-
"type": "secret_text",
186-
"name": "<VARIABLE_NAME>",
187-
"text": "<SECRET_VALUE>"
188-
},
189-
{
190-
"type": "service",
191-
"name": "<VARIABLE_NAME>",
192-
"service": "<SERVICE_NAME>",
193-
"environment": "production"
194-
},
195-
{
196-
"type": "tail_consumer",
197-
"service": "<WORKER_NAME>"
198-
},
199-
{
200-
"type": "vectorize",
201-
"name": "<VARIABLE_NAME>",
202-
"index_name": "<INDEX_NAME>"
203-
},
204-
{
205-
"type": "version_metadata",
206-
"name": "<VARIABLE_NAME>"
207-
}
208-
]
119+
"bindings": [
120+
{
121+
"type": "ai",
122+
"name": "<VARIABLE_NAME>"
123+
},
124+
{
125+
"type": "analytics_engine",
126+
"name": "<VARIABLE_NAME>",
127+
"dataset": "<DATASET>"
128+
},
129+
{
130+
"type": "assets",
131+
"name": "<VARIABLE_NAME>"
132+
},
133+
{
134+
"type": "browser_rendering",
135+
"name": "<VARIABLE_NAME>"
136+
},
137+
{
138+
"type": "d1",
139+
"name": "<VARIABLE_NAME>",
140+
"id": "<D1_ID>"
141+
},
142+
{
143+
"type": "durable_object_namespace",
144+
"name": "<VARIABLE_NAME>",
145+
"class_name": "<DO_CLASS_NAME>"
146+
},
147+
{
148+
"type": "hyperdrive",
149+
"name": "<VARIABLE_NAME>",
150+
"id": "<HYPERDRIVE_ID>"
151+
},
152+
{
153+
"type": "kv_namespace",
154+
"name": "<VARIABLE_NAME>",
155+
"namespace_id": "<KV_ID>"
156+
},
157+
{
158+
"type": "mtls_certificate",
159+
"name": "<VARIABLE_NAME>",
160+
"certificate_id": "<MTLS_CERTIFICATE_ID>"
161+
},
162+
{
163+
"type": "plain_text",
164+
"name": "<VARIABLE_NAME>",
165+
"text": "<VARIABLE_VALUE>"
166+
},
167+
{
168+
"type": "queue",
169+
"name": "<VARIABLE_NAME>",
170+
"queue_name": "<QUEUE_NAME>"
171+
},
172+
{
173+
"type": "r2_bucket",
174+
"name": "<VARIABLE_NAME>",
175+
"bucket_name": "<R2_BUCKET_NAME>"
176+
},
177+
{
178+
"type": "secret_text",
179+
"name": "<VARIABLE_NAME>",
180+
"text": "<SECRET_VALUE>"
181+
},
182+
{
183+
"type": "service",
184+
"name": "<VARIABLE_NAME>",
185+
"service": "<SERVICE_NAME>",
186+
"environment": "production"
187+
},
188+
{
189+
"type": "tail_consumer",
190+
"service": "<WORKER_NAME>"
191+
},
192+
{
193+
"type": "vectorize",
194+
"name": "<VARIABLE_NAME>",
195+
"index_name": "<INDEX_NAME>"
196+
},
197+
{
198+
"type": "version_metadata",
199+
"name": "<VARIABLE_NAME>"
200+
}
201+
]
209202
}
210203
```

0 commit comments

Comments
 (0)