Class ClientBase
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
optionsClientOptionsThe client options containing the base endpoint.
authAuthorizationOptionsThe authorization options containing the API key.
Exceptions
- ArgumentNullException
Thrown when
optionsisnull.- ArgumentNullException
Thrown when
authisnull.
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
httpHttpClientThe HTTP client.
authorizationIAuthorizationThe authorization provider.
Exceptions
- ArgumentNullException
Thrown when
httpisnull.- ArgumentNullException
Thrown when
authorizationisnull.
Properties
HttpClient
The HTTP client used for requests.
protected HttpClient HttpClient { get; }
Property Value
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 cancellation = default)
Parameters
relativestringThe relative request URL.
parserIParser<TContract>The parser for deserializing the response.
acceptHeaderstringThe acceptance header value.
queryParamsQueryParametersOptional query parameters.
cancellationCancellationTokenThe cancellation token.
Returns
- Task<TContract>
The parsed response.
Type Parameters
TContractThe type to parse the response into.
Exceptions
- ArgumentNullException
Thrown when
parserisnull.- HttpRequestException
Thrown when the API responds with a non-success status code.
- OperationCanceledException
Thrown when the operation is canceled via
cancellation.