Class RestClientBase
Shared base class for REST clients. It implements common functionality for REST based communication over HTTP.
Namespace: DNVGL.One.Compute.RestClient
Assembly: DNVGL.One.Compute.WorkerHost.Kernel.Azure.dll
Syntax
public abstract class RestClientBase : object
Constructors
View SourceRestClientBase(Nullable<TimeSpan>)
Initializes a new instance of the RestClientBase class.
Declaration
protected RestClientBase(TimeSpan? httpClientTimeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Nullable<TimeSpan> | httpClientTimeout | The HTTP client timeout. |
Properties
View SourceGetAccessTokenCallbackAsync
Gets or sets an access token provider callback function.
Declaration
protected Func<Task<string>> GetAccessTokenCallbackAsync { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Task<System.String>> |
Remarks
If no such callback function is provided, the HTTP client will just assume that the token has been set already, by the REST client implementation.
HttpClient
Gets the HTTP client used for the REST calls.
Declaration
protected HttpClient HttpClient { get; }
Property Value
| Type | Description |
|---|---|
| HttpClient |
Methods
View SourceGetAsync(String, CancellationToken)
Gets the resource at the specified path.
Declaration
protected async Task<dynamic> GetAsync(string path, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path of the resource to retrieve. |
| CancellationToken | cancellationToken | A cancellation token that can be used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<System.Object> | A dynamic object representing the response content or 'default' on error or on empty response content. |
GetAsync<T>(String, CancellationToken)
Gets the resource of the specified type from the specified REST API path.
Declaration
protected async Task<T> GetAsync<T>(string path, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path of the resource to retrieve. |
| CancellationToken | cancellationToken | A cancellation token that can be used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<T> | The response content deserialized to the specified type or default{T} on error or on empty response content. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the response content. |
PostAsync(String, Object, CancellationToken)
Posts the specified body at the specified path.
Declaration
protected async Task<HttpResponseMessage> PostAsync(string path, object body, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | path | The path. |
| System.Object | body | The body. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> | The response message. |