Class HttpClientJsonExtensions
Helper methods for IHttpClient
Inherited Members
Namespace: Unity.Cloud.Common
Syntax
public static class HttpClientJsonExtensionsMethods
DeleteJsonAsync(IHttpClient, String, Object, CancellationToken)
Asynchronously performs a Delete-request, using Json to serialize payload/>
Declaration
public static Task<HttpResponseMessage> DeleteJsonAsync(this IHttpClient httpClient, string requestUri, object payload, CancellationToken cancellationToken = default(CancellationToken))Parameters
| Type | Name | Description | 
|---|---|---|
| IHttpClient | httpClient | The HTTP client. | 
| String | requestUri | The Uri the request is sent to | 
| Object | payload | Optional Object that will be used as content of the request message | 
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| Task<HttpResponseMessage> | A task that will hold the HttpResponseMessage once the request is completed | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown when the requestUri is null or empty. | 
| 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. | 
DeleteJsonAsync<TModel>(IHttpClient, String, Object, CancellationToken)
Asynchronously performs a Delete-request, using Json to serialize payload and deserialize response to a TModel
Declaration
public static async Task<TModel> DeleteJsonAsync<TModel>(this IHttpClient httpClient, string requestUri, object payload = null, CancellationToken cancellationToken = default(CancellationToken))Parameters
| Type | Name | Description | 
|---|---|---|
| IHttpClient | httpClient | The HTTP client. | 
| String | requestUri | The Uri the request is sent to | 
| Object | payload | Optional Object that will be used as content of the request message | 
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| Task<TModel> | A task that will hold the  | 
Type Parameters
| Name | Description | 
|---|---|
| TModel | The type the response is deserialized to | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown when the requestUri is null or empty. | 
| 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. | 
GetJsonAsync<TModel>(IHttpClient, String, CancellationToken)
Asynchronously performs a Get-request using Json to deserialize response to a TModel
Declaration
public static async Task<TModel> GetJsonAsync<TModel>(this IHttpClient httpClient, string requestUri, CancellationToken cancellationToken = default(CancellationToken))Parameters
| Type | Name | Description | 
|---|---|---|
| IHttpClient | httpClient | The HTTP client. | 
| String | requestUri | The Uri the request is sent to | 
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| Task<TModel> | A task that will hold the  | 
Type Parameters
| Name | Description | 
|---|---|
| TModel | The type the response is deserialized to | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown when the requestUri is null or empty. | 
| 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. | 
PatchJsonAsync<TModel>(IHttpClient, String, Object, CancellationToken)
Asynchronously performs a Patch-request, using Json to serialize payload and deserialize response to a TModel
Declaration
public static async Task<TModel> PatchJsonAsync<TModel>(this IHttpClient httpClient, string requestUri, object payload = null, CancellationToken cancellationToken = default(CancellationToken))Parameters
| Type | Name | Description | 
|---|---|---|
| IHttpClient | httpClient | The HTTP client. | 
| String | requestUri | The Uri the request is sent to | 
| Object | payload | Optional Object that will be used as content of the request message | 
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| Task<TModel> | A task that will hold the  | 
Type Parameters
| Name | Description | 
|---|---|
| TModel | The type the response is deserialized to | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown when the requestUri is null or empty. | 
| 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. | 
PostJsonAsync<TModel>(IHttpClient, String, Object, CancellationToken)
Asynchronously performs a Post-request, using Json to serialize payload and deserialize response to a TModel
Declaration
public static async Task<TModel> PostJsonAsync<TModel>(this IHttpClient httpClient, string requestUri, object payload = null, CancellationToken cancellationToken = default(CancellationToken))Parameters
| Type | Name | Description | 
|---|---|---|
| IHttpClient | httpClient | The HTTP client. | 
| String | requestUri | The Uri the request is sent to | 
| Object | payload | Optional Object that will be used as content of the request message | 
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| Task<TModel> | A task that will hold the  | 
Type Parameters
| Name | Description | 
|---|---|
| TModel | The type the response is deserialized to | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown when the requestUri is null or empty. | 
| 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. | 
PutJsonAsync<TModel>(IHttpClient, String, Object, CancellationToken)
Asynchronously performs a Put-request, using Json to serialize payload and deserialize response to a TModel
Declaration
public static async Task<TModel> PutJsonAsync<TModel>(this IHttpClient httpClient, string requestUri, object payload = null, CancellationToken cancellationToken = default(CancellationToken))Parameters
| Type | Name | Description | 
|---|---|---|
| IHttpClient | httpClient | The HTTP client. | 
| String | requestUri | The Uri the request is sent to | 
| Object | payload | Optional Object that will be used as content of the request message | 
| CancellationToken | cancellationToken | Optional cancellation token that will try to cancel the operation. | 
Returns
| Type | Description | 
|---|---|
| Task<TModel> | A task that will hold the  | 
Type Parameters
| Name | Description | 
|---|---|
| TModel | The type the response is deserialized to | 
Exceptions
| Type | Condition | 
|---|---|
| ArgumentException | Thrown when the requestUri is null or empty. | 
| 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. |