Skip to content

Commit c787df4

Browse files
Add code sample to fetch argument option
1 parent a628841 commit c787df4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/content/docs/secrets-store/integrations/workers.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,22 @@ export default {
9999

100100
### Pass `env` as an argument to `fetch`
101101

102+
```js
103+
export default {
104+
async fetch(request, env) {
105+
// Example of using the secret safely in an API request
106+
let response = await fetch("https://api.example.com/data", {
107+
headers: { "Authorization": `Bearer ${env.MY_SECRETS_STORE_SECRET}` },
108+
});
109+
110+
if (!response.ok) {
111+
return new Response("Failed to fetch data", { status: response.status });
112+
}
113+
114+
let data = await response.json();
115+
return new Response(JSON.stringify(data), {
116+
headers: { "Content-Type": "application/json" },
117+
});
118+
},
119+
};
120+
```

0 commit comments

Comments
 (0)