RESTCLIENT.NET
Menu
EN
↗ GitHub

RESTCLIENT.NET / API REFERENCE

RestClient.Net.HttpClientExtensions

All API types · RestClient.Net · View source

public static class HttpClientExtensions

Extension methods for HttpClient that return Result{TOk, TError}.

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/HttpClientExtensions.cs:477

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/HttpClientExtensions.cs:382

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/HttpClientExtensions.cs:508

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/HttpClientExtensions.cs:413

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/HttpClientExtensions.cs:445

DeleteAsync

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

Performs a DELETE request.

Parameter Type Default Description
httpClient HttpClient Required The HTTP client to use.
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/HttpClientExtensions.cs:195

DownloadFileAsync

public static Task<Result<Unit, HttpError<TError>>> DownloadFileAsync<TError>(this HttpClient httpClient, 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
httpClient HttpClient Required The HTTP client.
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/HttpClientExtensions.cs:316

GetAsync

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

Performs a GET request.

Parameter Type Default Description
httpClient HttpClient Required The HTTP client to use.
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/HttpClientExtensions.cs:101

HeadAsync

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

Performs a HEAD request.

Parameter Type Default Description
httpClient HttpClient Required The HTTP client to use.
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/HttpClientExtensions.cs:257

OptionsAsync

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

Performs an OPTIONS request.

Parameter Type Default Description
httpClient HttpClient Required The HTTP client to use.
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/HttpClientExtensions.cs:287

PatchAsync

public static Task<Result<TSuccess, HttpError<TError>>> PatchAsync<TSuccess, TError>(this HttpClient httpClient, 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
httpClient HttpClient Required The HTTP client to use.
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/HttpClientExtensions.cs:226

PostAsync

public static Task<Result<TSuccess, HttpError<TError>>> PostAsync<TSuccess, TError>(this HttpClient httpClient, 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
httpClient HttpClient Required The HTTP client to use.
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/HttpClientExtensions.cs:132

PutAsync

public static Task<Result<TSuccess, HttpError<TError>>> PutAsync<TSuccess, TError>(this HttpClient httpClient, 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
httpClient HttpClient Required The HTTP client to use.
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/HttpClientExtensions.cs:164

SendAsync

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

Sends an HTTP request asynchronously using the specified HTTP operation.

Parameter Type Default Description
httpClient HttpClient Required The HTTP client.
url AbsoluteUrl Required The URL to send the request to.
httpMethod HttpMethod Required The HTTP method to use.
deserializeSuccess Deserialize<TSuccess> Required Function to deserialize a successful response.
deserializeError Deserialize<TError> Required Function to deserialize an error response.
headers IReadOnlyDictionary<string, string>? Required The headers to include in the request (optional).
requestBody HttpContent? null The request body stream (optional).
httpOperation HttpAction? null The HTTP operation to perform (optional). This only necessary if you need to override the default.
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/HttpClientExtensions.cs:26

UploadFileAsync

public static Task<Result<TSuccess, HttpError<TError>>> UploadFileAsync<TSuccess, TError>(this HttpClient httpClient, AbsoluteUrl url, HttpContent requestBody, 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
httpClient HttpClient Required The HTTP client.
url AbsoluteUrl Required The URL to upload the file to.
requestBody HttpContent 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/HttpClientExtensions.cs:352