RESTCLIENT.NET
Menu
EN
↗ GitHub

RESTCLIENT.NET / API REFERENCE

RestClient.Net.HttpClientFactoryExtensions

All API types · RestClient.Net · View source

public static class HttpClientFactoryExtensions

Provides extension methods for IHttpClientFactory to simplify HTTP operations.

Members

CreateDelete

public static DeleteAsync<TSuccess, TError, TParam> CreateDelete<TSuccess, TError, TParam>(AbsoluteUrl url, BuildRequest<TParam> buildRequest, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError);

Creates a DELETE request delegate for the specified URL.

Parameter Type Default Description
url AbsoluteUrl Required The absolute URL for the DELETE request.
buildRequest BuildRequest<TParam> Required Function to build the request parts from parameters.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize successful HTTP responses.
deserializeError Deserialize<TError> Required Function to deserialize error HTTP responses.

Type parameter TSuccess: The type to deserialize successful responses to.

Type parameter TError: The type to deserialize error responses to.

Type parameter TParam: The type of parameter used to construct the request.

Returns: A delegate that can execute the DELETE request with the specified parameters.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:383

CreateGet

public static GetAsync<TSuccess, TError, TParam> CreateGet<TSuccess, TError, TParam>(AbsoluteUrl url, BuildRequest<TParam> buildRequest, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError);

Creates a GET request delegate for the specified URL.

Parameter Type Default Description
url AbsoluteUrl Required The absolute URL for the GET request.
buildRequest BuildRequest<TParam> Required Function to build the request parts from parameters.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize successful HTTP responses.
deserializeError Deserialize<TError> Required Function to deserialize error HTTP responses.

Type parameter TSuccess: The type to deserialize successful responses to.

Type parameter TError: The type to deserialize error responses to.

Type parameter TParam: The type of parameter used to construct the request.

Returns: A delegate that can execute the GET request with the specified parameters.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:288

CreateHead

public static HeadAsync<TSuccess, TError, TParam> CreateHead<TSuccess, TError, TParam>(AbsoluteUrl url, BuildRequest<TParam> buildRequest, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError);

Creates a HEAD request delegate for the specified URL.

Parameter Type Default Description
url AbsoluteUrl Required The absolute URL for the HEAD request.
buildRequest BuildRequest<TParam> Required Function to build the request parts from parameters.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize successful HTTP responses.
deserializeError Deserialize<TError> Required Function to deserialize error HTTP responses.

Type parameter TSuccess: The type to deserialize successful responses to.

Type parameter TError: The type to deserialize error responses to.

Type parameter TParam: The type of parameter used to construct the request.

Returns: A delegate that can execute the HEAD request with the specified parameters.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:446

CreateOptions

public static OptionsAsync<TSuccess, TError, TParam> CreateOptions<TSuccess, TError, TParam>(AbsoluteUrl url, BuildRequest<TParam> buildRequest, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError);

Creates an OPTIONS request delegate for the specified URL.

Parameter Type Default Description
url AbsoluteUrl Required The absolute URL for the OPTIONS request.
buildRequest BuildRequest<TParam> Required Function to build the request parts from parameters.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize successful HTTP responses.
deserializeError Deserialize<TError> Required Function to deserialize error HTTP responses.

Type parameter TSuccess: The type to deserialize successful responses to.

Type parameter TError: The type to deserialize error responses to.

Type parameter TParam: The type of parameter used to construct the request.

Returns: A delegate that can execute the OPTIONS request with the specified parameters.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:477

CreatePatch

public static PatchAsync<TSuccess, TError, TParam> CreatePatch<TSuccess, TError, TParam>(AbsoluteUrl url, BuildRequest<TParam> buildRequest, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError);

Creates a PATCH request delegate for the specified URL.

Parameter Type Default Description
url AbsoluteUrl Required The absolute URL for the PATCH request.
buildRequest BuildRequest<TParam> Required Function to build the request parts from parameters.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize successful HTTP responses.
deserializeError Deserialize<TError> Required Function to deserialize error HTTP responses.

Type parameter TSuccess: The type to deserialize successful responses to.

Type parameter TError: The type to deserialize error responses to.

Type parameter TParam: The type of parameter used to construct the request.

Returns: A delegate that can execute the PATCH request with the specified parameters.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:414

CreatePost

public static PostAsync<TSuccess, TError, TParam> CreatePost<TSuccess, TError, TParam>(AbsoluteUrl url, BuildRequest<TParam> buildRequest, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError);

Creates a POST request delegate for the specified URL.

Parameter Type Default Description
url AbsoluteUrl Required The absolute URL for the POST request.
buildRequest BuildRequest<TParam> Required Function to build the request parts from parameters.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize successful HTTP responses.
deserializeError Deserialize<TError> Required Function to deserialize error HTTP responses.

Type parameter TSuccess: The type to deserialize successful responses to.

Type parameter TError: The type to deserialize error responses to.

Type parameter TParam: The type of parameter used to construct the request.

Returns: A delegate that can execute the POST request with the specified parameters.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:319

CreatePut

public static PutAsync<TSuccess, TError, TParam> CreatePut<TSuccess, TError, TParam>(AbsoluteUrl url, BuildRequest<TParam> buildRequest, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError);

Creates a PUT request delegate for the specified URL.

Parameter Type Default Description
url AbsoluteUrl Required The absolute URL for the PUT request.
buildRequest BuildRequest<TParam> Required Function to build the request parts from parameters.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize successful HTTP responses.
deserializeError Deserialize<TError> Required Function to deserialize error HTTP responses.

Type parameter TSuccess: The type to deserialize successful responses to.

Type parameter TError: The type to deserialize error responses to.

Type parameter TParam: The type of parameter used to construct the request.

Returns: A delegate that can execute the PUT request with the specified parameters.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:351

DeleteAsync

public static Task<Result<TSuccess, HttpError<TError>>> DeleteAsync<TSuccess, TError>(this IHttpClientFactory httpClientFactory, string clientName, AbsoluteUrl url, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError, IReadOnlyDictionary<string, string>? headers = null, CancellationToken cancellationToken = default);

Performs a DELETE request.

Parameter Type Default Description
httpClientFactory IHttpClientFactory Required The HTTP client factory instance.
clientName string Required The name of the client to create.
url AbsoluteUrl Required The URL to send the request to.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize a successful response.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
headers IReadOnlyDictionary<string, string>? null The headers to include in the request (optional).
cancellationToken CancellationToken default A token to cancel the operation.

Type parameter TSuccess: The type representing a successful response.

Type parameter TError: The type representing an error response.

Returns: A Result containing either the successful response or an HTTP error.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:163

DownloadFileAsync

public static Task<Result<Unit, HttpError<TError>>> DownloadFileAsync<TError>(this IHttpClientFactory httpClientFactory, string clientName, AbsoluteUrl url, Stream destinationStream, Deserialize<TError> deserializeError, IReadOnlyDictionary<string, string>? headers = null, CancellationToken cancellationToken = default);

Downloads a file from the specified URL to a stream.

Parameter Type Default Description
httpClientFactory IHttpClientFactory Required The HTTP client factory instance.
clientName string Required The name of the client to create.
url AbsoluteUrl Required The URL to download the file from.
destinationStream Stream Required The stream to write the downloaded file to.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
headers IReadOnlyDictionary<string, string>? null The headers to include in the request (optional).
cancellationToken CancellationToken default A token to cancel the operation.

Type parameter TError: The type representing an error response.

Returns: A Result containing either a Unit value on success or an HTTP error.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:188

GetAsync

public static Task<Result<TSuccess, HttpError<TError>>> GetAsync<TSuccess, TError>(this IHttpClientFactory httpClientFactory, string clientName, AbsoluteUrl url, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError, IReadOnlyDictionary<string, string>? headers = null, CancellationToken cancellationToken = default);

Performs a GET request.

Parameter Type Default Description
httpClientFactory IHttpClientFactory Required The HTTP client factory instance.
clientName string Required The name of the client to create.
url AbsoluteUrl Required The URL to send the request to.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize a successful response.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
headers IReadOnlyDictionary<string, string>? null The headers to include in the request (optional).
cancellationToken CancellationToken default A token to cancel the operation.

Type parameter TSuccess: The type representing a successful response.

Type parameter TError: The type representing an error response.

Returns: A Result containing either the successful response or an HTTP error.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:67

PatchAsync

public static Task<Result<TSuccess, HttpError<TError>>> PatchAsync<TSuccess, TError>(this IHttpClientFactory httpClientFactory, string clientName, AbsoluteUrl url, HttpContent requestBody, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError, IReadOnlyDictionary<string, string>? headers = null, CancellationToken cancellationToken = default);

Performs a PATCH request.

Parameter Type Default Description
httpClientFactory IHttpClientFactory Required The HTTP client factory instance.
clientName string Required The name of the client to create.
url AbsoluteUrl Required The URL to send the request to.
requestBody HttpContent Required The content to send in the request body.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize a successful response.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
headers IReadOnlyDictionary<string, string>? null The headers to include in the request (optional).
cancellationToken CancellationToken default A token to cancel the operation.

Type parameter TSuccess: The type representing a successful response.

Type parameter TError: The type representing an error response.

Returns: A Result containing either the successful response or an HTTP error.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:256

PostAsync

public static Task<Result<TSuccess, HttpError<TError>>> PostAsync<TSuccess, TError>(this IHttpClientFactory httpClientFactory, string clientName, AbsoluteUrl url, HttpContent? requestBody, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError, IReadOnlyDictionary<string, string>? headers = null, CancellationToken cancellationToken = default);

Performs a POST request.

Parameter Type Default Description
httpClientFactory IHttpClientFactory Required The HTTP client factory instance.
clientName string Required The name of the client to create.
url AbsoluteUrl Required The URL to send the request to.
requestBody HttpContent? Required The content to send in the request body.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize a successful response.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
headers IReadOnlyDictionary<string, string>? null The headers to include in the request (optional).
cancellationToken CancellationToken default A token to cancel the operation.

Type parameter TSuccess: The type representing a successful response.

Type parameter TError: The type representing an error response.

Returns: A Result containing either the successful response or an HTTP error.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:94

PutAsync

public static Task<Result<TSuccess, HttpError<TError>>> PutAsync<TSuccess, TError>(this IHttpClientFactory httpClientFactory, string clientName, AbsoluteUrl url, HttpContent? requestBody, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError, IReadOnlyDictionary<string, string>? headers = null, CancellationToken cancellationToken = default);

Performs a PUT request.

Parameter Type Default Description
httpClientFactory IHttpClientFactory Required The HTTP client factory instance.
clientName string Required The name of the client to create.
url AbsoluteUrl Required The URL to send the request to.
requestBody HttpContent? Required The content to send in the request body.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize a successful response.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
headers IReadOnlyDictionary<string, string>? null The headers to include in the request (optional).
cancellationToken CancellationToken default A token to cancel the operation.

Type parameter TSuccess: The type representing a successful response.

Type parameter TError: The type representing an error response.

Returns: A Result containing either the successful response or an HTTP error.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:129

SendAsync

public static async Task<Result<TSuccess, HttpError<TError>>> SendAsync<TSuccess, TError>(this IHttpClientFactory httpClientFactory, string clientName, AbsoluteUrl url, HttpMethod httpMethod, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError, HttpContent? requestBody = null, IReadOnlyDictionary<string, string>? headers = null, HttpAction? httpOperation = null, CancellationToken cancellationToken = default);

Sends an HTTP request asynchronously using the specified HTTP operation.

Parameter Type Default Description
httpClientFactory IHttpClientFactory Required The HTTP client factory.
clientName string Required The name of the client to create.
url AbsoluteUrl Required The URL to send the request to.
httpMethod HttpMethod Required The HTTP method to use for the request.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize a successful response.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
requestBody HttpContent? null The request body stream (optional).
headers IReadOnlyDictionary<string, string>? null The headers to include in the request (optional).
httpOperation HttpAction? null An optional action to configure the HttpClient before sending the request.
cancellationToken CancellationToken default A token to cancel the operation.

Type parameter TSuccess: The type of the successful response.

Type parameter TError: The type of the error response.

Returns: A Result containing either the successful response or an HTTP error.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:28

UploadFileAsync

public static Task<Result<TSuccess, HttpError<TError>>> UploadFileAsync<TSuccess, TError>(this IHttpClientFactory httpClientFactory, string clientName, AbsoluteUrl url, ProgressReportingHttpContent fileStream, Deserialize<TSuccess> deserializeSuccess, Deserialize<TError> deserializeError, IReadOnlyDictionary<string, string>? headers = null, CancellationToken cancellationToken = default);

Uploads a file to the specified URL.

Parameter Type Default Description
httpClientFactory IHttpClientFactory Required The HTTP client factory instance.
clientName string Required The name of the client to create.
url AbsoluteUrl Required The URL to upload the file to.
fileStream ProgressReportingHttpContent Required The file content to upload.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize a successful response.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
headers IReadOnlyDictionary<string, string>? null The headers to include in the request (optional).
cancellationToken CancellationToken default A token to cancel the operation.

Type parameter TSuccess: The type representing a successful response.

Type parameter TError: The type representing an error response.

Returns: A Result containing either the successful response or an HTTP error.

View source: RestClient.Net/HttpClientFactoryExtensions.cs:221