0

Retrieve an Existing Read-only Replica

by
Published Dec 20, 2024

To show information about an existing database replica, send a GET request to `/v2/databases/$DATABASE_ID/replicas/$REPLICA_NAME`. **Note**: Read-only replicas are not supported for Redis clusters. The response will be a JSON object with a `replica key`. This will be set to an object containing the standard database replica attributes.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Retrieve an Existing Read-only Replica
7
 * To show information about an existing database replica, send a GET request to `/v2/databases/$DATABASE_ID/replicas/$REPLICA_NAME`.
8

9
**Note**: Read-only replicas are not supported for Redis clusters.
10

11
The response will be a JSON object with a `replica key`. This will be set to an object containing the standard database replica attributes.
12
 */
13
export async function main(
14
  auth: Digitalocean,
15
  database_cluster_uuid: string,
16
  replica_name: string,
17
) {
18
  const url = new URL(
19
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/replicas/${replica_name}`,
20
  );
21

22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35