Skip to content

Repository files navigation

Soenneker.DigitalOcean.HttpClients

Provides a cached HttpClient configured for DigitalOcean’s API base address and bearer authentication.

Installation

dotnet add package Soenneker.DigitalOcean.HttpClients

Configuration

{
  "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.

Registration and use

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.

About

A thread-safe singleton HttpClient for DigitalOcean's OpenAPI integration.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages