-
Notifications
You must be signed in to change notification settings - Fork 10k
Add Workers for Platforms bindings documentation #22975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
babc0b2
docs: add Workers for Platforms bindings documentation
dinasaur404 342ccb8
Update bindings.mdx
dinasaur404 6fe9f3c
Update src/content/docs/cloudflare-for-platforms/workers-for-platform…
dinasaur404 d385b8d
Update src/content/docs/cloudflare-for-platforms/workers-for-platform…
dinasaur404 d9add4e
Address PR feedback on Workers for Platforms bindings documentation
dinasaur404 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
143 changes: 143 additions & 0 deletions
143
...nt/docs/cloudflare-for-platforms/workers-for-platforms/get-started/bindings.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,143 @@ | ||||||
| --- | ||||||
| pcx_content_type: how-to | ||||||
| title: Bindings | ||||||
| sidebar: | ||||||
| order: 5 | ||||||
| --- | ||||||
| import { Aside } from "@astrojs/starlight/components"; | ||||||
|
|
||||||
| [Bindings](/workers/runtime-apis/bindings/) are resources (KV store, database, etc.) that you can attach to User Workers to enable end customers to build more powerful applications. By utilizing bindings, you can extend Cloudflare's developer platform to your end customers without needing to build the infrastructure components yourself. | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| With bindings, your users can: | ||||||
| - Use [KV](/kv/) for high-read, eventually consistent key-value storage | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - Use [D1](/d1/) for relational data and complex queries | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - Store large files and assets in [R2](/r2/) | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - Run AI inference using [Workers AI](/workers-ai/) | ||||||
| - Gain observability via [Analytics Engine](/analytics/analytics-engine/) | ||||||
| - Manage stateful coordination with [Durable Objects](/durable-objects/) | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| #### Resource isolation | ||||||
|
|
||||||
| Each Worker can only access the bindings that are explicitly attached to it. For full isolation, you can attach a unique resource (like a D1 database or KV namespace) to every User Worker. If multiple Workers need to access the same data, you can reuse a shared resource, but every Worker will still have its own binding to that shared resource. | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
|  | ||||||
|
|
||||||
| ## Adding Bindings to User Workers | ||||||
| You can attach [bindings](/workers/runtime-apis/bindings/) to User Workers to give them access to resources like D1, KV, R2, or Workers Analytics Engine. This section explains how to create and attach those resources so they can be used from the User Worker. | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| ### 1. Create the resources | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| For most bindings (e.g. KV, D1, R2, or Durable Objects), you'll first need to create the resource using the Wrangler CLI or Cloudflare API. This will generate a resource ID that you'll use when attaching the binding to the Worker in the next step. | ||||||
|
|
||||||
| Some bindings, like Workers AI or Workers Analytics Engine, don’t require you to create a resource in advance. If you're using one of those, you can skip this step and go directly to Step 2. | ||||||
|
|
||||||
| :::note | ||||||
| For every product, be sure to check product specific limits. Some resources may require contacting Support to request limit increases. | ||||||
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| ::: | ||||||
|
|
||||||
| ### 2. Attach the binding to the User Worker | ||||||
|
|
||||||
| #### Using the API | ||||||
|
|
||||||
| Use the [Upload User Worker API](http://localhost:1111/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/methods/update/) to attach bindings to a Worker. You can do this when you're first uploading the Worker script or when updating an existing Worker. | ||||||
|
||||||
| Use the [Upload User Worker API](http://localhost:1111/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/methods/update/) to attach bindings to a Worker. You can do this when you're first uploading the Worker script or when updating an existing Worker. | |
| Use the [Upload User Worker API](/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/methods/update/) to attach bindings to a Worker. You can do this when you're first uploading the Worker script or when updating an existing Worker. |
irvinebroque marked this conversation as resolved.
Show resolved
Hide resolved
irvinebroque marked this conversation as resolved.
Show resolved
Hide resolved
irvinebroque marked this conversation as resolved.
Show resolved
Hide resolved
irvinebroque marked this conversation as resolved.
Show resolved
Hide resolved
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dinasaur404 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dinasaur404 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
irvinebroque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dinasaur404 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dinasaur404 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.