//native
type Digitalocean = {
token: string;
};
/**
* Remove Droplets from a Load Balancer
* To remove a Droplet from a load balancer instance, send a DELETE request to
`/v2/load_balancers/$LOAD_BALANCER_ID/droplets`. In the body of the request,
there should be a `droplet_ids` attribute containing a list of Droplet IDs.
No response body will be sent back, but the response code will indicate
success. Specifically, the response code will be a 204, which means that the
action was successful with no returned body data.
*/
export async function main(
auth: Digitalocean,
lb_id: string,
body: { droplet_ids: number[] },
) {
const url = new URL(
`https://api.digitalocean.com/v2/load_balancers/${lb_id}/droplets`,
);
const response = await fetch(url, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago