Class BaseClient
- Namespace
- GenerativeAI.Clients
- Assembly
- GenerativeAI.dll
Represents the base implementation for API clients that interact with an underlying platform. This class provides shared functionality such as HTTP communication and authorization handling to its derived client classes.
public class BaseClient : ApiBase
- Inheritance
-
BaseClient
- Derived
- Inherited Members
- Extension Methods
Constructors
BaseClient(IPlatformAdapter, HttpClient?, ILogger?)
Represents the base client class that provides foundational functionality for API clients.
public BaseClient(IPlatformAdapter platform, HttpClient? httpClient, ILogger? logger = null)
Parameters
platformIPlatformAdapterhttpClientHttpClientloggerILogger
Remarks
This class serves as an abstraction layer for managing HTTP requests and interactions with platform-specific implementations. It encapsulates functionality for handling authorization, logging, and platform-specific operations through the use of dependency injection for IPlatformAdapter.
Properties
Platform
Gets the platform adapter associated with the client.
public IPlatformAdapter Platform { get; }
Property Value
Remarks
Provides access to the platform-specific functionality including authorization handling, URL generation, API versioning, and other platform-dependent operations. The platform is initialized when the client is instantiated and can be used by derived classes to interact with underlying platform APIs.
Methods
AddAuthorizationHeader(HttpRequestMessage, bool, CancellationToken)
Adds authorization headers to an HTTP request.
protected override Task AddAuthorizationHeader(HttpRequestMessage request, bool requireAccessToken = false, CancellationToken cancellationToken = default)
Parameters
requestHttpRequestMessageThe HTTP request where headers will be added.
requireAccessTokenboolWhether an access token is required for the request.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
Remarks
Override this method in derived classes to dynamically add authorization headers. By default, this implementation does nothing.