Skip to content

Commit 6f83aa9

Browse files
committed
Adding note on creating an API token.
1 parent 5d5de41 commit 6f83aa9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/content/docs/d1/best-practices/read-replication.mdx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To checkout D1 read replication and Sessions API:
1818

1919
[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/lambrospetrou/d1-starter-sessions-api)
2020

21-
2. Enable read replication on the just created D1 database:
21+
2. Enable read replication on the just created D1 database.
2222

2323
```curl
2424
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/d1/database/{database_id}" \
@@ -27,6 +27,12 @@ curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/d1/datab
2727
-d '{"read_replication": {"mode": "auto"}}'
2828
```
2929

30+
:::note
31+
To use REST API, you need to have an API token with `D1:Edit` permission.
32+
33+
If you do not have an API token, follow the guide: [Create API token](/fundamentals/api/get-started/create-token/).
34+
:::
35+
3036
```ts collapse={1-6, 34-130}
3137
import { D1Database, D1DatabaseSession } from "@cloudflare/workers-types";
3238

@@ -183,7 +189,7 @@ All write queries are still forwarded to the primary database instance. Read rep
183189
| Primary database instance | The database instance containing the “original” copy of the database | Can serve write queries | Can serve read queries |
184190
| Read replica database instance | A database instance containing a copy of the original database which asynchronously receives updates from the primary database instance | Forwards any write queries to the primary database instance | Can serve read queries using its own copy of the database |
185191

186-
## Sessions API examples
192+
## Use Sessions API
187193

188194
By using [Sessions API](/d1/worker-api/d1-database/#withsession) for read replication, all of your queries from a single <GlossaryTooltip term="session">Session</GlossaryTooltip> read from a version of the database which ensures sequential consistency. This ensures that the version of the database you are reading is logically consistent even if the queries are handled by different read replicas.
189195

@@ -192,7 +198,12 @@ D1 read replication achieves this by attaching a <GlossaryTooltip term="bookmark
192198
### Enable read replication
193199

194200
With the REST API, set `read_replication.mode: auto` to enable read replication on a D1 database.
195-
Use an [API token](/fundamentals/api/get-started/create-token/) with `D1:Edit` [permission](/fundamentals/api/reference/permissions/#account-permissions).
201+
202+
:::note
203+
To use REST API, you need to have an API token with `D1:Edit` permission.
204+
205+
If you do not have an API token, follow the guide: [Create API token](/fundamentals/api/get-started/create-token/).
206+
:::
196207

197208
<Tabs>
198209
<TabItem label="cURL">
@@ -203,6 +214,7 @@ curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/d1/datab
203214
-d '{"read_replication": {"mode": "auto"}}'
204215
```
205216
</TabItem><TabItem label="TypeScript">
217+
206218
```ts
207219
const headers = new Headers({
208220
"Authorization": `Bearer ${TOKEN}`

0 commit comments

Comments
 (0)