Show / Hide Table of Contents

Class RestClientBase

Shared base class for REST clients. It implements common functionality for REST based communication over HTTP.

Inheritance
object
RestClientBase
OneComputePlatformClient
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DNVGL.One.Compute.RestClient
Assembly: DNVGL.One.Compute.Platform.Client.dll
Syntax
public abstract class RestClientBase

Constructors

View Source

RestClientBase(TimeSpan?)

Initializes a new instance of the RestClientBase class.

Declaration
protected RestClientBase(TimeSpan? httpClientTimeout = null)
Parameters
Type Name Description
TimeSpan? httpClientTimeout

The HTTP client timeout.

Properties

View Source

GetAccessTokenCallbackAsync

Gets or sets an access token provider callback function.

Declaration
protected Func<Task<string>> GetAccessTokenCallbackAsync { get; set; }
Property Value
Type Description
Func<Task<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.

View Source

HttpClient

Gets the HTTP client used for the REST calls.

Declaration
protected HttpClient HttpClient { get; }
Property Value
Type Description
HttpClient

Methods

View Source

GetAsync(string, CancellationToken)

Gets the resource at the specified path.

Declaration
protected Task<dynamic> GetAsync(string path, CancellationToken cancellationToken = default)
Parameters
Type Name Description
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<dynamic>

A dynamic object representing the response content or 'default' on error or on empty response content.

Exceptions
Type Condition
HttpRequestException

Thrown when an error occurs while sending the HTTP request.

InvalidOperationException

Thrown when the response status code is not in the 2xx or 3xx range and cannot be handled by the current implementation.

UnauthorizedAccessException

Thrown when the response status code is 401 or 403, indicating that the user does not have access to the resource.

View Source

GetAsync<T>(string, CancellationToken)

Gets the resource of the specified type from the specified REST API path.

Declaration
protected Task<T> GetAsync<T>(string path, CancellationToken cancellationToken = default)
Parameters
Type Name Description
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.

Exceptions
Type Condition
HttpRequestException

Thrown when an error occurs while sending the HTTP request.

InvalidOperationException

Thrown when the response status code is not in the 2xx or 3xx range and cannot be handled by the current implementation.

UnauthorizedAccessException

Thrown when the response status code is 401 or 403, indicating that the user does not have access to the resource.

View Source

PostAsync(string, object, CancellationToken)

Posts the specified body at the specified path.

Declaration
protected Task<HttpResponseMessage> PostAsync(string path, object body, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string path

The path.

object body

The body.

CancellationToken cancellationToken

The cancellation token.

Returns
Type Description
Task<HttpResponseMessage>

The response message.

  • View Source
In this article
Back to top Copyright © DNV AS. All rights reserved.