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.AzureBatch.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 SourceHttpClient
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. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<System.Object> | The response content, null if the resource is not found. |
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 within the REST API. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<T> | The response content deserialized to the specified type or default{T} if the resource is not found. |
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. |