Provides a cached HttpClient configured for DigitalOcean’s API base address and bearer authentication.
dotnet add package Soenneker.DigitalOcean.HttpClients{
"DigitalOcean": {
"AccessToken": "your-personal-access-token"
}
}Store the token in user secrets, environment-backed configuration, or a secret manager rather than source control.
Optional settings:
{
"DigitalOcean": {
"ClientBaseUrl": "https://api.digitalocean.com",
"AuthHeaderName": "Authorization",
"AuthHeaderValueTemplate": "Bearer {token}"
}
}The template replaces every literal {token} with AccessToken. Treat ClientBaseUrl, the header name, and the template as trusted configuration: the resulting authentication header is sent to that base address.
using Soenneker.DigitalOcean.HttpClients.Abstract;
using Soenneker.DigitalOcean.HttpClients.Registrars;
services.AddDigitalOceanOpenApiHttpClientAsSingleton();
public sealed class DropletReader(IDigitalOceanOpenApiHttpClient clientProvider)
{
public async Task<string> GetDroplets(CancellationToken cancellationToken)
{
HttpClient client = await clientProvider.Get(cancellationToken);
return await client.GetStringAsync("/v2/droplets", cancellationToken);
}
}Get returns the cached client; do not dispose that HttpClient yourself. The provider owns it and removes it from the cache when the provider is disposed.
AddDigitalOceanOpenApiHttpClientAsScoped() creates a separately owned cached client for each scope. Disposing a scope removes only that provider's client. Use singleton registration when one client should live for the application lifetime.
This package configures transport only. It does not deserialize DigitalOcean responses, follow pagination links, or translate non-success status codes. Use the companion OpenAPI client/util packages or handle those concerns in the caller.