HttpRestClientFormExtensions Class

Namespace
Kampute.HttpClient
Assembly
  • Kampute.HttpClient.dll

Definition

Provides extension methods for HttpRestClient to support sending HTTP requests with URL-encoded form content.
public static class HttpRestClientFormExtensions
Inheritance
  • object
  • HttpRestClientFormExtensions

Remarks

This static class extends HttpRestClient functionality by adding methods for sending HTTP requests with content type 'application/x-www-form-urlencoded'.

Methods

PatchAsFormAsync<T>(this HttpRestClient, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)

Sends an asynchronous PATCH request with URL-encoded form content to the specified URI and returns the response body deserialized as the specified type.
public static Task<T> PatchAsFormAsync<T>(
	this HttpRestClient client,
	string uri,
	IEnumerable<KeyValuePair<string, string>> payload,
	CancellationToken cancellationToken = default)

Type Parameters

T
The type of the response object.

Parameters

client HttpRestClient
The HttpRestClient instance to be used for sending the request.
uri string
The URI to which the request is sent.
payload IEnumerable<KeyValuePair<string, string>>
The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task<T>
A task that represents the asynchronous operation, with a result of the specified type.

Exceptions

ArgumentNullException
Thrown if uri or payload is null.
HttpResponseException
Thrown if the response status code indicates a failure.
HttpRequestException
Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.
HttpContentException
Thrown if the response body is empty or its media type is not supported.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token.

PatchAsFormAsync(this HttpRestClient, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)

Sends an asynchronous PATCH request with URL-encoded form content to the specified URI without processing the response body.
public static Task PatchAsFormAsync(
	this HttpRestClient client,
	string uri,
	IEnumerable<KeyValuePair<string, string>> payload,
	CancellationToken cancellationToken = default)

Parameters

client HttpRestClient
The HttpRestClient instance to be used for sending the request.
uri string
The URI to which the request is sent.
payload IEnumerable<KeyValuePair<string, string>>
The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task
A task that represents the asynchronous operation.

Exceptions

ArgumentNullException
Thrown if uri or payload is null.
HttpResponseException
Thrown if the response status code indicates a failure.
HttpRequestException
Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.
HttpContentException
Thrown if the response body is empty or its media type is not supported.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token.

PostAsFormAsync<T>(this HttpRestClient, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)

Sends an asynchronous POST request with URL-encoded form content to the specified URI.
public static Task<T> PostAsFormAsync<T>(
	this HttpRestClient client,
	string uri,
	IEnumerable<KeyValuePair<string, string>> payload,
	CancellationToken cancellationToken = default)

Type Parameters

T
The type of the object expected in the response.

Parameters

client HttpRestClient
The HttpRestClient instance to be used for sending the request.
uri string
The URI to which the request is sent.
payload IEnumerable<KeyValuePair<string, string>>
The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task<T>
A task representing the asynchronous operation, returning a deserialized object of type T.

Exceptions

ArgumentNullException
Thrown if uri or payload is null.
HttpResponseException
Thrown if the response status code indicates a failure.
HttpRequestException
Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.
HttpContentException
Thrown if the response body is empty or its media type is not supported.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token.

PostAsFormAsync(this HttpRestClient, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)

Sends an asynchronous POST request with URL-encoded form content to the specified URI without processing the response body.
public static Task PostAsFormAsync(
	this HttpRestClient client,
	string uri,
	IEnumerable<KeyValuePair<string, string>> payload,
	CancellationToken cancellationToken = default)

Parameters

client HttpRestClient
The HttpRestClient instance to be used for sending the request.
uri string
The URI to which the request is sent.
payload IEnumerable<KeyValuePair<string, string>>
The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task
A task that represents the asynchronous operation.

Exceptions

ArgumentNullException
Thrown if uri or payload is null.
HttpResponseException
Thrown if the response status code indicates a failure.
HttpRequestException
Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.
HttpContentException
Thrown if the response body is empty or its media type is not supported.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token.

PutAsFormAsync<T>(this HttpRestClient, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)

Sends an asynchronous PUT request with URL-encoded form content to the specified URI and returns the response body deserialized as the specified type.
public static Task<T> PutAsFormAsync<T>(
	this HttpRestClient client,
	string uri,
	IEnumerable<KeyValuePair<string, string>> payload,
	CancellationToken cancellationToken = default)

Type Parameters

T
The type of the response object.

Parameters

client HttpRestClient
The HttpRestClient instance to be used for sending the request.
uri string
The URI to which the request is sent.
payload IEnumerable<KeyValuePair<string, string>>
The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task<T>
A task that represents the asynchronous operation, with a result of the specified type.

Exceptions

ArgumentNullException
Thrown if uri or payload is null.
HttpResponseException
Thrown if the response status code indicates a failure.
HttpRequestException
Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.
HttpContentException
Thrown if the response body is empty or its media type is not supported.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token.

PutAsFormAsync(this HttpRestClient, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)

Sends an asynchronous PUT request with URL-encoded form content to the specified URI without processing the response body.
public static Task PutAsFormAsync(
	this HttpRestClient client,
	string uri,
	IEnumerable<KeyValuePair<string, string>> payload,
	CancellationToken cancellationToken = default)

Parameters

client HttpRestClient
The HttpRestClient instance to be used for sending the request.
uri string
The URI to which the request is sent.
payload IEnumerable<KeyValuePair<string, string>>
The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task
A task that represents the asynchronous operation.

Exceptions

ArgumentNullException
Thrown if uri or payload is null.
HttpResponseException
Thrown if the response status code indicates a failure.
HttpRequestException
Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.
HttpContentException
Thrown if the response body is empty or its media type is not supported.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token.

SendAsFormAsync<T>(this HttpRestClient, HttpMethod, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)

Sends an asynchronous request with URL-encoded form content to the specified URI.
public static Task<T> SendAsFormAsync<T>(
	this HttpRestClient client,
	HttpMethod method,
	string uri,
	IEnumerable<KeyValuePair<string, string>> payload,
	CancellationToken cancellationToken = default)

Type Parameters

T
The type of the object expected in the response.

Parameters

client HttpRestClient
The HttpRestClient instance to be used for sending the request.
method HttpMethod
The HTTP method to use for the request.
uri string
The URI to which the request is sent.
payload IEnumerable<KeyValuePair<string, string>>
The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task<T>
A task representing the asynchronous operation, returning a deserialized object of type T.

Exceptions

ArgumentNullException
Thrown if method, uri or payload is null.
HttpResponseException
Thrown if the response status code indicates a failure.
HttpRequestException
Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.
HttpContentException
Thrown if the response body is empty or its media type is not supported.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token.

SendAsFormAsync(this HttpRestClient, HttpMethod, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)

Sends an asynchronous POST request with URL-encoded form content to the specified URI without processing the response body.
public static Task SendAsFormAsync(
	this HttpRestClient client,
	HttpMethod method,
	string uri,
	IEnumerable<KeyValuePair<string, string>> payload,
	CancellationToken cancellationToken = default)

Parameters

client HttpRestClient
The HttpRestClient instance to be used for sending the request.
method HttpMethod
The HTTP method to use for the request.
uri string
The URI to which the request is sent.
payload IEnumerable<KeyValuePair<string, string>>
The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task
A task representing the asynchronous operation.

Exceptions

ArgumentNullException
Thrown if method, uri or payload is null.
HttpResponseException
Thrown if the response status code indicates a failure.
HttpRequestException
Thrown if the request fails due to an underlying issue such as network connectivity, DNS failure, server certificate validation, or timeout.
HttpContentException
Thrown if the response body is empty or its media type is not supported.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token.