Class ServiceHttpClientExtensions
Helper methods for IServiceHttpClient.
Inherited Members
Namespace: Unity.Cloud.Common
Syntax
public static class ServiceHttpClientExtensions
Methods
DeleteAsync(IServiceHttpClient, String, HttpContent, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous DELETE request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this IServiceHttpClient httpClient, string requestUri, HttpContent content, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| String | requestUri | The uri for the request. |
| HttpContent | content | The HTTP content for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the requestUri is invalid. |
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
DeleteAsync(IServiceHttpClient, String, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous DELETE request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this IServiceHttpClient httpClient, string requestUri, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| String | requestUri | The uri for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the requestUri is invalid. |
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
DeleteAsync(IServiceHttpClient, Uri, HttpContent, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous DELETE request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this IServiceHttpClient httpClient, Uri requestUri, HttpContent content, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| Uri | requestUri | The uri for the request. |
| HttpContent | content | The HTTP content for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
DeleteAsync(IServiceHttpClient, Uri, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous DELETE request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> DeleteAsync(this IServiceHttpClient httpClient, Uri requestUri, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| Uri | requestUri | The uri for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
GetAsync(IServiceHttpClient, String, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous GET request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> GetAsync(this IServiceHttpClient httpClient, string requestUri, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| String | requestUri | The uri for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the requestUri is invalid. |
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
GetAsync(IServiceHttpClient, Uri, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous GET request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> GetAsync(this IServiceHttpClient httpClient, Uri requestUri, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| Uri | requestUri | The uri for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
PostAsync(IServiceHttpClient, String, HttpContent, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous POST request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PostAsync(this IServiceHttpClient httpClient, string requestUri, HttpContent content, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| String | requestUri | The uri for the request. |
| HttpContent | content | The HTTP content for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the requestUri is invalid. |
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
PostAsync(IServiceHttpClient, Uri, HttpContent, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous POST request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PostAsync(this IServiceHttpClient httpClient, Uri requestUri, HttpContent content, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| Uri | requestUri | The uri for the request. |
| HttpContent | content | The HTTP content for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
PutAsync(IServiceHttpClient, String, HttpContent, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous PUT request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PutAsync(this IServiceHttpClient httpClient, string requestUri, HttpContent content, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| String | requestUri | The uri for the request. |
| HttpContent | content | The HTTP content for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the requestUri is invalid. |
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
PutAsync(IServiceHttpClient, Uri, HttpContent, ServiceHttpClientOptions, CancellationToken)
Sends an asynchronous PUT request to the specified Uri.
Declaration
public static Task<HttpResponseMessage> PutAsync(this IServiceHttpClient httpClient, Uri requestUri, HttpContent content, ServiceHttpClientOptions options, CancellationToken cancellationToken = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | httpClient | The HTTP client. |
| Uri | requestUri | The uri for the request. |
| HttpContent | content | The HTTP content for the request. |
| ServiceHttpClientOptions | options | The options for the client. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
Exceptions
| Type | Condition |
|---|---|
| HttpRequestException | Thrown when an HTTP response can't be obtained from the server. |
| TaskCanceledException | Thrown when the request is cancelled by a cancellation token. |
| TimeoutException | Thrown when the request failed due to timeout. |
WithApiSourceHeaders(IServiceHttpClient, String, String)
Creates an instance of Unity.Cloud.Common.ServiceHttpClientHeaderModifier which adds the API source headers to each request.
Declaration
public static IServiceHttpClient WithApiSourceHeaders(this IServiceHttpClient baseServiceHttpClient, string name, string version)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | baseServiceHttpClient | The client for which to modify the request headers. |
| String | name | The API source name. |
| String | version | The API source version. |
Returns
| Type | Description |
|---|---|
| IServiceHttpClient | The created Unity.Cloud.Common.ServiceHttpClientHeaderModifier. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown is |
WithApiSourceHeadersFromAssembly(IServiceHttpClient, Assembly)
Creates an instance of Unity.Cloud.Common.ServiceHttpClientHeaderModifier which adds the API source headers to each request. The source values are retrieved from the ApiSourceVersionAttribute which must be defined in the calling Assembly.
Declaration
public static IServiceHttpClient WithApiSourceHeadersFromAssembly(this IServiceHttpClient baseServiceHttpClient, Assembly assembly)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceHttpClient | baseServiceHttpClient | The client for which to modify the request headers. |
| Assembly | assembly | The target assembly. |
Returns
| Type | Description |
|---|---|
| IServiceHttpClient | The created Unity.Cloud.Common.ServiceHttpClientHeaderModifier. |
Remarks
An instance of the ApiSourceVersionAttribute must be defined at the assembly-level in the calling Assembly in order for the correct API source values to be added as a header.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| InvalidOperationException | Thrown if ApiSourceVersionAttribute does not exist or is not initialized in the calling assembly. |
| InvalidArgumentException | Thrown if ApiSourceVersionAttribute is initialized with null or empty values in the calling assembly. |