Class OpenBiApiClient
- Namespace
- BiExcellence.OpenBi.Api
- Assembly
- BiExcellence.OpenBi.Api.Client.dll
Default IOpenBiApiClient implementation, backed by an System.Net.Http.HttpClient.
public sealed class OpenBiApiClient : IOpenBiApiClient
- Inheritance
-
objectOpenBiApiClient
- Implements
- Extension Methods
-
OpenBiApiClientApiKeyExtensions.CreateApiKeySecretAsync(IOpenBiApiClient, string, CancellationToken)OpenBiApiClientBatchJobExtensions.CreateBatchJobAsync(IOpenBiApiClient, BatchJob, CancellationToken)OpenBiApiClientBlogExtensions.DeleteContentArticleAsync(IOpenBiApiClient, string, CancellationToken)OpenBiApiClientDownloadExtensions.CreateDownloadAsync(IOpenBiApiClient, Download, CancellationToken)OpenBiApiClientMasterDataExtensions.GetHierarchiesAsync(IOpenBiApiClient, string, CancellationToken)OpenBiApiClientOAuthAppExtensions.CreateOAuthAppAsync(IOpenBiApiClient, OAuthApp, CancellationToken)OpenBiApiClientRoleExtensions.GetRolesAsync(IOpenBiApiClient, OpenBiListRequest?, CancellationToken)OpenBiApiClientUsergroupExtensions.DeleteUsergroupAsync(IOpenBiApiClient, string, CancellationToken)
Constructors
OpenBiApiClient(HttpClient, bool)
Creates a client that wraps an existing System.Net.Http.HttpClient (for example one obtained from
IHttpClientFactory). Its System.Net.Http.HttpClient.BaseAddress must already be set.
public OpenBiApiClient(HttpClient httpClient, bool disposeHttpClient = false)
Parameters
httpClientHttpClientThe System.Net.Http.HttpClient to use for all requests.
disposeHttpClientboolWhether disposing this client should also dispose
httpClient. Defaults to false, matching the usualIHttpClientFactoryownership model.
OpenBiApiClient(Uri, HttpMessageHandler?)
Creates a client that owns its own System.Net.Http.HttpClient, targeting the given REST API base address.
public OpenBiApiClient(Uri baseAddress, HttpMessageHandler? handler = null)
Parameters
baseAddressUriThe REST API's base address, e.g.
https://myserver/openbi/api/. A trailing slash is added automatically if missing.handlerHttpMessageHandlerAn optional message handler (useful for tests); ownership is transferred to the created System.Net.Http.HttpClient.
Properties
AccessToken
The bearer access token currently attached to outgoing requests, or null if none has been set.
public string? AccessToken { get; }
Property Value
- string
BaseAddress
The REST API's base address, e.g. https://myserver/openbi/api/.
public Uri BaseAddress { get; }
Property Value
- Uri
Methods
DeleteAsync(string, CancellationToken)
Sends a DELETE request.
public Task DeleteAsync(string requestUri, CancellationToken cancellationToken = default)
Parameters
requestUristringcancellationTokenCancellationToken
Returns
- Task
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetAsync<TResponse>(string, CancellationToken)
Sends a GET request and deserializes the JSON response body.
public Task<TResponse?> GetAsync<TResponse>(string requestUri, CancellationToken cancellationToken = default)
Parameters
requestUristringcancellationTokenCancellationToken
Returns
- Task<TResponse>
Type Parameters
TResponse
GetFileAsync(string, CancellationToken)
Sends a GET request and returns the response body as a file: the stream plus the media type and file name the server stated. Use this where the response is a document rather than JSON.
public Task<OpenBiApiFile> GetFileAsync(string requestUri, CancellationToken cancellationToken = default)
Parameters
requestUristringThe relative request URI.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<OpenBiApiFile>
The file. Disposing it disposes the underlying response.
GetListAsync<TItem>(string, CancellationToken)
Sends a GET request against a list endpoint and returns its items together with the X-Total-Count response header, when present.
public Task<OpenBiListResult<TItem>> GetListAsync<TItem>(string requestUri, CancellationToken cancellationToken = default)
Parameters
requestUristringcancellationTokenCancellationToken
Returns
- Task<OpenBiListResult<TItem>>
Type Parameters
TItem
GetStreamAsync(string, CancellationToken)
Sends a GET request and returns the raw response stream (e.g. for file downloads).
The caller owns and must dispose the returned stream.
public Task<Stream> GetStreamAsync(string requestUri, CancellationToken cancellationToken = default)
Parameters
requestUristringcancellationTokenCancellationToken
Returns
- Task<Stream>
PostAsync(string, CancellationToken)
Sends a POST request with no body.
public Task PostAsync(string requestUri, CancellationToken cancellationToken = default)
Parameters
requestUristringcancellationTokenCancellationToken
Returns
- Task
PostAsync<TRequest>(string, TRequest?, CancellationToken)
Sends a POST request with a JSON body and no response body.
public Task PostAsync<TRequest>(string requestUri, TRequest? body, CancellationToken cancellationToken = default)
Parameters
requestUristringbodyTRequestcancellationTokenCancellationToken
Returns
- Task
Type Parameters
TRequest
PostAsync<TRequest, TResponse>(string, TRequest?, CancellationToken)
Sends a POST request with a JSON body and deserializes the JSON response body.
public Task<TResponse?> PostAsync<TRequest, TResponse>(string requestUri, TRequest? body, CancellationToken cancellationToken = default)
Parameters
requestUristringbodyTRequestcancellationTokenCancellationToken
Returns
- Task<TResponse>
Type Parameters
TRequestTResponse
PostFileAsync<TResponse>(string, Stream, string, IEnumerable<KeyValuePair<string, string>>?, CancellationToken)
Sends a multipart/form-data POST carrying one file plus optional text fields, and
deserializes the JSON response body. The file is streamed rather than buffered.
public Task<TResponse?> PostFileAsync<TResponse>(string requestUri, Stream stream, string fileName, IEnumerable<KeyValuePair<string, string>>? fields = null, CancellationToken cancellationToken = default)
Parameters
requestUristringstreamStreamfileNamestringfieldsIEnumerable<KeyValuePair<string, string>>cancellationTokenCancellationToken
Returns
- Task<TResponse>
Type Parameters
TResponse
PostFormAsync(string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)
Sends a POST request with an application/x-www-form-urlencoded body and no response body
(used by /oauth/revoke).
public Task PostFormAsync(string requestUri, IEnumerable<KeyValuePair<string, string>> form, CancellationToken cancellationToken = default)
Parameters
requestUristringformIEnumerable<KeyValuePair<string, string>>cancellationTokenCancellationToken
Returns
- Task
PostFormAsync<TResponse>(string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)
Sends a POST request with an application/x-www-form-urlencoded body (used by the
/oauth/token and /oauth/revoke endpoints) and deserializes the JSON response body.
public Task<TResponse?> PostFormAsync<TResponse>(string requestUri, IEnumerable<KeyValuePair<string, string>> form, CancellationToken cancellationToken = default)
Parameters
requestUristringformIEnumerable<KeyValuePair<string, string>>cancellationTokenCancellationToken
Returns
- Task<TResponse>
Type Parameters
TResponse
PostServerSentEventsAsync<TRequest, TItem>(string, TRequest?, CancellationToken)
Sends a POST request with a JSON body, asking the server for a server-sent event stream, and
yields each event's deserialized payload as it arrives. The stream stays open until the server closes
it, so enumeration lasts as long as the operation being reported on.
public IAsyncEnumerable<TItem> PostServerSentEventsAsync<TRequest, TItem>(string requestUri, TRequest? body, CancellationToken cancellationToken = default)
Parameters
requestUristringbodyTRequestcancellationTokenCancellationToken
Returns
- IAsyncEnumerable<TItem>
Type Parameters
TRequestTItem
QueryListAsync<TRequest, TItem>(string, TRequest?, CancellationToken)
Sends a QUERY request with a JSON body and reads the response as a list. The QUERY-method form of a list route takes the same options as the query string does, for filters that do not fit in a URL.
public Task<OpenBiListResult<TItem>> QueryListAsync<TRequest, TItem>(string requestUri, TRequest? body, CancellationToken cancellationToken = default)
Parameters
requestUristringThe relative request URI.
bodyTRequestThe query options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<OpenBiListResult<TItem>>
Type Parameters
TRequestThe request body type.
TItemThe item type to deserialize each entry into.
SetAccessToken(string?)
Attaches (or clears, when accessToken is null) the bearer access token used to authorize subsequent requests.
public void SetAccessToken(string? accessToken)
Parameters
accessTokenstring