Skip to content

Commit b6b7d21

Browse files
committed
Using embedded tabs to also showcase wrangler file.
1 parent b2bf10d commit b6b7d21

File tree

1 file changed

+51
-38
lines changed

1 file changed

+51
-38
lines changed

src/content/docs/kv/index.mdx

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,7 @@ sidebar:
55
order: 1
66
---
77

8-
import {
9-
CardGrid,
10-
Description,
11-
Feature,
12-
LinkTitleCard,
13-
Plan,
14-
RelatedProduct,
15-
Tabs,
16-
TabItem,
17-
LinkButton
18-
} from "~/components";
8+
import { CardGrid, Description, Feature, LinkTitleCard, Plan, RelatedProduct, Tabs, TabItem, LinkButton } from "~/components";
199

2010
<Description>
2111

@@ -44,33 +34,56 @@ Access your Workers KV namespace from Cloudflare Workers using the Workers Bindi
4434

4535
<Tabs>
4636
<TabItem label="Workers Binding API">
47-
```ts
48-
export default {
49-
async fetch(request, env, ctx): Promise<Response> {
50-
51-
//write a key-value pair
52-
await env.KV_BINDING.put('KEY', 'VALUE');
53-
54-
// read a key-value pair
55-
const value = await env.KV_BINDING.get('KEY');
56-
57-
//list all key-value pairs
58-
const allKeys = await env.KV_BINDING.list();
59-
60-
//delete a key-value pair
61-
await env.KV_BINDING.delete('KEY');
62-
63-
//return a Workers response
64-
return new Response(
65-
JSON.stringify({
66-
value: value,
67-
allKeys: allKeys,
68-
}),
69-
);
70-
},
71-
};
72-
73-
```
37+
<Tabs>
38+
<TabItem label="index.ts">
39+
```ts
40+
export default {
41+
async fetch(request, env, ctx): Promise<Response> {
42+
43+
//write a key-value pair
44+
await env.KV_BINDING.put('KEY', 'VALUE');
45+
46+
// read a key-value pair
47+
const value = await env.KV_BINDING.get('KEY');
48+
49+
//list all key-value pairs
50+
const allKeys = await env.KV_BINDING.list();
51+
52+
//delete a key-value pair
53+
await env.KV_BINDING.delete('KEY');
54+
55+
//return a Workers response
56+
return new Response(
57+
JSON.stringify({
58+
value: value,
59+
allKeys: allKeys,
60+
}),
61+
);
62+
},
63+
};
64+
65+
```
66+
</TabItem>
67+
<TabItem label="wrangler.jsonc">
68+
```json
69+
{
70+
"$schema": "node_modules/wrangler/config-schema.json",
71+
"name": "WORKER-NAME",
72+
"main": "src/index.ts",
73+
"compatibility_date": "2025-02-04",
74+
"observability": {
75+
"enabled": true
76+
},
77+
78+
"kv_namespaces": [
79+
{
80+
"binding": "YOUR_BINDING",
81+
"id": "<YOUR_BINDING_ID>"
82+
}
83+
]
84+
```
85+
</TabItem>
86+
</Tabs>
7487
</TabItem>
7588
<TabItem label="REST API">
7689
```

0 commit comments

Comments
 (0)