Table of Contents

Class ClientBase

Namespace
DotBahn.Common.Clients
Assembly
DotBahn.Common.dll

Base class for API clients providing common HTTP functionality

public abstract class ClientBase : IDisposable
Inheritance
ClientBase
Implements
Derived
Inherited Members

Constructors

ClientBase(ClientOptions, AuthorizationOptions)

Initializes a new instance that creates and owns its own HttpClient

protected ClientBase(ClientOptions options, AuthorizationOptions auth)

Parameters

options ClientOptions

The client options containing the base endpoint

auth AuthorizationOptions

The authorization options containing the API key

Exceptions

ArgumentNullException

Thrown when options is null

ArgumentNullException

Thrown when auth is null

ClientBase(HttpClient, IAuthorization)

Initializes a new instance with the specified HTTP client and authorization. The HttpClient is not owned by this instance and will not be disposed

protected ClientBase(HttpClient http, IAuthorization authorization)

Parameters

http HttpClient

The HTTP client

authorization IAuthorization

The authorization provider

Exceptions

ArgumentNullException

Thrown when http is null

ArgumentNullException

Thrown when authorization is null

Properties

ApiName

The API identifier used for telemetry tags

protected virtual string ApiName { get; }

Property Value

string

HttpClient

The HTTP client used for requests

protected HttpClient HttpClient { get; }

Property Value

HttpClient

Methods

Dispose()

public void Dispose()

GetAsync<TContract>(string, IParser<TContract>, string, QueryParameters?, CancellationToken)

Performs a GET request and parses the response into the specified contract type

protected Task<TContract> GetAsync<TContract>(string relative, IParser<TContract> parser, string acceptHeader, QueryParameters? queryParams = null, CancellationToken ct = default)

Parameters

relative string

The relative request URL

parser IParser<TContract>

The parser for deserializing the response

acceptHeader string

The acceptance header value

queryParams QueryParameters

Optional query parameters

ct CancellationToken

The ct token

Returns

Task<TContract>

The parsed response

Type Parameters

TContract

The type to parse the response into

Exceptions

ArgumentNullException

Thrown when parser is null

HttpRequestException

Thrown when the API responds with a non-success status code

OperationCanceledException

Thrown when the operation is canceled via ct