Table of Contents

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
object
OpenBiApiClient
Implements
Extension Methods

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

httpClient HttpClient

The System.Net.Http.HttpClient to use for all requests.

disposeHttpClient bool

Whether disposing this client should also dispose httpClient. Defaults to false, matching the usual IHttpClientFactory ownership 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

baseAddress Uri

The REST API's base address, e.g. https://myserver/openbi/api/. A trailing slash is added automatically if missing.

handler HttpMessageHandler

An 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

requestUri string
cancellationToken CancellationToken

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

requestUri string
cancellationToken CancellationToken

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

requestUri string

The relative request URI.

cancellationToken CancellationToken

A 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

requestUri string
cancellationToken CancellationToken

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

requestUri string
cancellationToken CancellationToken

Returns

Task<Stream>

PostAsync(string, CancellationToken)

Sends a POST request with no body.

public Task PostAsync(string requestUri, CancellationToken cancellationToken = default)

Parameters

requestUri string
cancellationToken CancellationToken

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

requestUri string
body TRequest
cancellationToken CancellationToken

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

requestUri string
body TRequest
cancellationToken CancellationToken

Returns

Task<TResponse>

Type Parameters

TRequest
TResponse

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

requestUri string
stream Stream
fileName string
fields IEnumerable<KeyValuePair<string, string>>
cancellationToken CancellationToken

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

requestUri string
form IEnumerable<KeyValuePair<string, string>>
cancellationToken CancellationToken

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

requestUri string
form IEnumerable<KeyValuePair<string, string>>
cancellationToken CancellationToken

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

requestUri string
body TRequest
cancellationToken CancellationToken

Returns

IAsyncEnumerable<TItem>

Type Parameters

TRequest
TItem

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

requestUri string

The relative request URI.

body TRequest

The query options.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<OpenBiListResult<TItem>>

Type Parameters

TRequest

The request body type.

TItem

The 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

accessToken string