Class HttpClientExtensions
Extensions for the HttpClient class
Inheritance
Inherited Members
Namespace: Dapplo.HttpExtensions
Assembly: Dapplo.HttpExtensions.dll
Syntax
public static class HttpClientExtensions
Methods
| Improve this Doc View SourceAddDefaultRequestHeader(HttpClient, String, String)
Add default request header without validation
Declaration
public static HttpClient AddDefaultRequestHeader(this HttpClient client, string name, string value)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | HttpClient |
System.String | name | Header name |
System.String | value | Header value |
Returns
Type | Description |
---|---|
HttpClient | HttpClient for fluent usage |
DeleteAsync(HttpClient, Uri, CancellationToken)
Send a Delete request to the server
Declaration
public static Task DeleteAsync(this HttpClient httpClient, Uri uri, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | HttpClient |
Uri | uri | Uri to send the delete request to |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task | Task |
DeleteAsync<TResponse>(HttpClient, Uri, CancellationToken)
Send a Delete request to the server
Declaration
public static async Task<TResponse> DeleteAsync<TResponse>(this HttpClient httpClient, Uri uri, CancellationToken cancellationToken = null)
where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | HttpClient |
Uri | uri | Uri to send the delete request to |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task<TResponse> | TResult |
Type Parameters
Name | Description |
---|---|
TResponse | the generic type to return the result into, use HttpContent or HttpResponseMessage to get those unprocessed |
GetAsAsync<TResponse>(HttpClient, Uri, CancellationToken)
Get the content from the specified uri via the HttpClient read into a Type object Currently we support Json objects which are annotated with the DataContract/DataMember attributes We might support other object, e.g MemoryStream, Bitmap etc soon
Declaration
public static async Task<TResponse> GetAsAsync<TResponse>(this HttpClient client, Uri uri, CancellationToken cancellationToken = null)
where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
HttpClient | client | HttpClient |
Uri | uri | URI |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task<TResponse> | the deserialized object of type T or default(T) |
Type Parameters
Name | Description |
---|---|
TResponse | The Type to read into |
HeadAsync(HttpClient, Uri, CancellationToken)
Retrieve only the content headers, by using the HTTP HEAD method
Declaration
public static async Task<HttpContentHeaders> HeadAsync(this HttpClient httpClient, Uri uri, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | |
Uri | uri | Uri to get HEAD for |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task<System.Net.Http.Headers.HttpContentHeaders> | HttpContentHeaders |
PatchAsync(HttpClient, Uri, Object, CancellationToken)
Patch the content, and don't expect (ignore) the response
Declaration
public static async Task PatchAsync(this HttpClient httpClient, Uri uri, object content, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | HttpClient |
Uri | uri | Uri to patch an empty request to |
System.Object | content | Content to patch |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task |
PatchAsync<TResponse>(HttpClient, Uri, Object, CancellationToken)
Patch the content, and get the reponse
Declaration
public static async Task<TResponse> PatchAsync<TResponse>(this HttpClient httpClient, Uri uri, object content, CancellationToken cancellationToken = null)
where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | HttpClient |
Uri | uri | Uri to patch request to |
System.Object | content | Content to patch |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task<TResponse> | TResult |
Type Parameters
Name | Description |
---|---|
TResponse | the generic type to return the result into, use HttpContent or HttpResponseMessage to get those unprocessed |
PostAsync(HttpClient, Uri, Object, CancellationToken)
Post the content, and don't expect (ignore) the response
Declaration
public static async Task PostAsync(this HttpClient httpClient, Uri uri, object content, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | HttpClient |
Uri | uri | Uri to post an empty request to |
System.Object | content | Content to post |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task |
PostAsync<TResponse>(HttpClient, Uri, Object, CancellationToken)
Post the content, and get the reponse
Declaration
public static async Task<TResponse> PostAsync<TResponse>(this HttpClient httpClient, Uri uri, object content, CancellationToken cancellationToken = null)
where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | HttpClient |
Uri | uri | Uri to post request to |
System.Object | content | Content to post |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task<TResponse> | TResult |
Type Parameters
Name | Description |
---|---|
TResponse | the generic type to return the result into, use HttpContent or HttpResponseMessage to get those unprocessed |
PutAsync(HttpClient, Uri, Object, CancellationToken)
Put the content, ignore the reponse
Declaration
public static async Task PutAsync(this HttpClient httpClient, Uri uri, object content, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | HttpClient |
Uri | uri | Uri to put the request to |
System.Object | content | Content to put |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task | Task |
PutAsync<TResponse>(HttpClient, Uri, Object, CancellationToken)
Put the content, and get the reponse
Declaration
public static async Task<TResponse> PutAsync<TResponse>(this HttpClient httpClient, Uri uri, object content, CancellationToken cancellationToken = null)
where TResponse : class
Parameters
Type | Name | Description |
---|---|---|
HttpClient | httpClient | HttpClient |
Uri | uri | Uri to put the request to |
System.Object | content | Content to put |
CancellationToken | cancellationToken | CancellationToken |
Returns
Type | Description |
---|---|
Task<TResponse> | TResult |
Type Parameters
Name | Description |
---|---|
TResponse | the generic type to return the result into, use HttpContent or HttpResponseMessage to get those unprocessed |