Class HttpRestClientFormExtensions
- Namespace
 - Kampute.HttpClient
 
- Assembly
 - Kampute.HttpClient.dll
 
Provides extension methods for HttpRestClient to support sending HTTP requests with URL-encoded form content.
public static class HttpRestClientFormExtensions
  - Inheritance
 - 
      
      HttpRestClientFormExtensions
 
- Inherited Members
 
Remarks
This static class extends HttpRestClient functionality by adding methods for sending HTTP requests with content type 'application/x-www-form-urlencoded'.
Methods
PatchAsFormAsync(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
clientHttpRestClientThe HttpRestClient instance to be used for sending the request.
uristringThe URI to which the request is sent.
payloadIEnumerable<KeyValuePair<string, string>>The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationTokenCancellationTokenA token for canceling the request (optional).
Returns
- Task
 A task that represents the asynchronous operation.
Exceptions
- ArgumentNullException
 Thrown if
uriorpayloadis 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<T>(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)
  Parameters
clientHttpRestClientThe HttpRestClient instance to be used for sending the request.
uristringThe URI to which the request is sent.
payloadIEnumerable<KeyValuePair<string, string>>The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationTokenCancellationTokenA token for canceling the request (optional).
Returns
- Task<T>
 A task that represents the asynchronous operation, with a result of the specified type.
Type Parameters
TThe type of the response object.
Exceptions
- ArgumentNullException
 Thrown if
uriorpayloadis 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(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
clientHttpRestClientThe HttpRestClient instance to be used for sending the request.
uristringThe URI to which the request is sent.
payloadIEnumerable<KeyValuePair<string, string>>The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationTokenCancellationTokenA token for canceling the request (optional).
Returns
- Task
 A task that represents the asynchronous operation.
Exceptions
- ArgumentNullException
 Thrown if
uriorpayloadis 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>(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)
  Parameters
clientHttpRestClientThe HttpRestClient instance to be used for sending the request.
uristringThe URI to which the request is sent.
payloadIEnumerable<KeyValuePair<string, string>>The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationTokenCancellationTokenA token for canceling the request (optional).
Returns
- Task<T>
 A task representing the asynchronous operation, returning a deserialized object of type
T.
Type Parameters
TThe type of the object expected in the response.
Exceptions
- ArgumentNullException
 Thrown if
uriorpayloadis 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(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
clientHttpRestClientThe HttpRestClient instance to be used for sending the request.
uristringThe URI to which the request is sent.
payloadIEnumerable<KeyValuePair<string, string>>The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationTokenCancellationTokenA token for canceling the request (optional).
Returns
- Task
 A task that represents the asynchronous operation.
Exceptions
- ArgumentNullException
 Thrown if
uriorpayloadis 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>(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)
  Parameters
clientHttpRestClientThe HttpRestClient instance to be used for sending the request.
uristringThe URI to which the request is sent.
payloadIEnumerable<KeyValuePair<string, string>>The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationTokenCancellationTokenA token for canceling the request (optional).
Returns
- Task<T>
 A task that represents the asynchronous operation, with a result of the specified type.
Type Parameters
TThe type of the response object.
Exceptions
- ArgumentNullException
 Thrown if
uriorpayloadis 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(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
clientHttpRestClientThe HttpRestClient instance to be used for sending the request.
methodHttpMethodThe HTTP method to use for the request.
uristringThe URI to which the request is sent.
payloadIEnumerable<KeyValuePair<string, string>>The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationTokenCancellationTokenA token for canceling the request (optional).
Returns
- Task
 A task representing the asynchronous operation.
Exceptions
- ArgumentNullException
 Thrown if
method,uriorpayloadis 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>(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)
  Parameters
clientHttpRestClientThe HttpRestClient instance to be used for sending the request.
methodHttpMethodThe HTTP method to use for the request.
uristringThe URI to which the request is sent.
payloadIEnumerable<KeyValuePair<string, string>>The collection of key-value pairs to serialize as the URL-encoded HTTP request payload.
cancellationTokenCancellationTokenA token for canceling the request (optional).
Returns
- Task<T>
 A task representing the asynchronous operation, returning a deserialized object of type
T.
Type Parameters
TThe type of the object expected in the response.
Exceptions
- ArgumentNullException
 Thrown if
method,uriorpayloadis 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.