HttpRestClient Class

Namespace
Kampute.HttpClient
Assembly
  • Kampute.HttpClient.dll

Definition

Sends requests to a REST API through an HttpClient, and converts between .NET objects and HTTP content.
public class HttpRestClient : IDisposable
Inheritance
Implements

Remarks

By default, every HttpRestClient uses one shared HttpClient, so clients created for different APIs reuse the same connections. A client can also use an HttpClient that the application creates and configures.

DefaultRequestHeaders apply to every request of the client. BeginHeaderScope(IEnumerable<KeyValuePair<string, string>>) and BeginPropertyScope(IEnumerable<KeyValuePair<string, object>>) add or override headers and request properties until the scope is disposed, without changing the defaults.

ContentFormatters read response content into .NET objects by its Content-Type, and write the payloads of SendObjectAsync<T>(this HttpRestClient, HttpMethod, string, object, string, CancellationToken). When a request sets no Accept header, the client sets one from the media types the formatters can read into the expected type.

Failures are recovered in two ways. RetryPolicy decides whether to retry after a transient connection failure or a timeout, and ErrorHandlers decide whether to retry after an error response. An error response that no handler retries is thrown as an HttpResponseException.

BeforeSendingRequest and AfterReceivingResponse let the application change or inspect each request and response, for example to add headers or to log.

Constructors

HttpRestClient()

Initializes a new instance of the HttpRestClient class that uses the shared HttpClient.
public HttpRestClient()

Remarks

The client acquires a reference to the HttpClient of SharedHttpClient and releases it when it is disposed. The shared HttpClient is disposed when its last reference is released.

HttpRestClient(SharedDisposable<HttpClient>.Reference)

Initializes a new instance of the HttpRestClient class that uses a shared HttpClient.
public HttpRestClient(SharedDisposable<HttpClient>.Reference httpClientReference)

Parameters

httpClientReference SharedDisposable<HttpClient>.Reference
A reference to the shared HttpClient. The client takes ownership of the reference and releases it when it is disposed.

Exceptions

ArgumentNullException
Thrown if httpClientReference is null.

HttpRestClient(HttpClient, bool)

Initializes a new instance of the HttpRestClient class with the specified HttpClient.
public HttpRestClient(HttpClient httpClient, bool disposeClient = true)

Parameters

httpClient HttpClient
The HttpClient that sends the requests of this client.
disposeClient bool optional
true to dispose httpClient when this client is disposed; false to leave it to its owner. The default is true.

Exceptions

ArgumentNullException
Thrown if httpClient is null.

Properties

BaseAddress

Gets or sets the base address of the requests.
public Uri BaseAddress { get; set; }

Property Value

Uri
The URI that relative request URIs are resolved against, or null if requests use absolute URIs.

Remarks

If the base address does not end with a slash, one is appended. Without it, the last segment of the path would be replaced when a relative URI is resolved: with http://example.com/api, the relative URI users would resolve to http://example.com/users instead of http://example.com/api/users.

When the base address is null, every request must use an absolute URI.

ContentFormatters

Gets the content formatters that read response content and write request payloads.
public HttpContentFormatterCollection ContentFormatters { get; }

Property Value

HttpContentFormatterCollection
The mutable collection of IHttpContentFormatter instances of this client.

Remarks

The formatters are tried in order. The first one that can read the media type of a response into the expected .NET type reads it, and the media types they can read feed the Accept header of requests that do not set one. The first one that can write a payload in the requested media type writes the payloads of SendObjectAsync<T>(this HttpRestClient, HttpMethod, string, object, string, CancellationToken).

The collection is empty initially. Format packages register their formatters with extension methods such as UseJson.

DefaultRequestHeaders

Gets the headers sent with every request of this client.
public HttpRequestHeaders DefaultRequestHeaders { get; }

Property Value

HttpRequestHeaders
The default request headers of this client.

Remarks

Headers of an active scope, begun with BeginHeaderScope(IEnumerable<KeyValuePair<string, string>>), override these headers.

HttpHeaders is not thread-safe. The client locks this collection while it copies the headers into each new request, and HttpError401Handler locks it while it updates the Authorization header. Code that changes this collection while requests are in flight must lock the same object.

Examples

This code replaces the access token while other requests may be in flight:
lock (client.DefaultRequestHeaders)
{
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthSchemes.Bearer, accessToken);
}

ErrorHandlers

Gets the error handlers that decide whether to retry a request after an error response.
public HttpErrorHandlerCollection ErrorHandlers { get; }

Property Value

HttpErrorHandlerCollection
The error handlers of this client.

Remarks

When a request receives an error response, the handlers whose IHttpErrorHandler.CanHandle(HttpStatusCode) accepts the status code are asked in the order they were added, until one of them returns a request to retry. If none does, the error is thrown as an HttpResponseException.

ResponseErrorType

Gets or sets the type into which the body of an error response is read.
public Type ResponseErrorType { get; set; }

Property Value

Type
The error model of the API, or null to leave the body of error responses unread.

Remarks

When this property is set, the client reads the body of an error response into this type with the formatters in ContentFormatters, and exposes the result through HttpResponseException.ResponseObject. If the body cannot be read, HttpResponseException.ResponseObject is null.

When the type implements IHttpErrorResponse, the object read from the body creates the exception, so it can carry the error details of the API, such as validation errors.

RetryPolicy

Gets or sets the retry policy for transient connection failures.
public IHttpRetryPolicy RetryPolicy { get; set; }

Property Value

IHttpRetryPolicy
The IHttpRetryPolicy that decides whether and when a request is retried after a transient connection failure or a timeout. The default is HttpRetryPolicy.None, which does not retry; setting null restores it.

Remarks

The policy applies when a request fails without a response, for example because the connection is refused or reset, the host cannot be reached, or HttpClient.Timeout elapses. Error responses, such as '503 Service Unavailable', are handled by ErrorHandlers instead.

The limits of the policy apply to the retries after connection failures only. Error handlers count their own retries separately, so a call that fails in several ways can be retried more times in total than this policy allows.

Examples

This policy retries a request up to five times after connection failures, with a delay that starts at one second and doubles each time:
client.RetryPolicy = RetryStrategies.Exponential(TimeSpan.FromSeconds(1)).WithMaxRetries(5).ToHttpRetryPolicy();

Methods

BeginHeaderScope(IEnumerable<KeyValuePair<string, string>>)

Begins a scope that sets or removes headers of the requests this client sends until the scope is disposed.
public virtual IDisposable BeginHeaderScope(IEnumerable<KeyValuePair<string, string>> headers)

Parameters

headers IEnumerable<KeyValuePair<string, string>>
The headers to set, or, with a null value, to remove.

Returns

IDisposable
An IDisposable that ends the scope when it is disposed.

Exceptions

ArgumentNullException
Thrown if headers is null.

Remarks

The headers of the scope replace the headers of the same name in DefaultRequestHeaders. A scope flows with the asynchronous context of the code that begins it: it applies to the requests that code makes, including in methods it awaits, but not to requests made concurrently by unrelated code. Scopes can be nested, and an inner scope overrides an outer one.

The HttpClient.DefaultRequestHeaders of the underlying HttpClient are added to a request only for the headers it does not already have, so a header that a scope removes is still sent if the HttpClient sets it. Keep the default headers of the HttpClient empty, and set them on DefaultRequestHeaders instead.

BeginPropertyScope(IEnumerable<KeyValuePair<string, object>>)

Begins a scope that sets or removes request properties of the requests this client sends until the scope is disposed.
public virtual IDisposable BeginPropertyScope(IEnumerable<KeyValuePair<string, object>> properties)

Parameters

properties IEnumerable<KeyValuePair<string, object>>
The properties to set, or, with a null value, to remove.

Returns

IDisposable
An IDisposable that ends the scope when it is disposed.

Exceptions

ArgumentNullException
Thrown if properties is null.

Remarks

Request properties carry values for message handlers and for the handlers of BeforeSendingRequest; they are not sent to the server.

A scope flows with the asynchronous context of the code that begins it: it applies to the requests that code makes, including in methods it awaits, but not to requests made concurrently by unrelated code. Scopes can be nested, and an inner scope overrides an outer one.

CreateHttpRequest(HttpMethod, string, Type)

Creates a request with the specified method and URI, and with the headers and properties of the client.
protected virtual HttpRequestMessage CreateHttpRequest(HttpMethod method, string uri, Type responseObjectType)

Parameters

method HttpMethod
The HTTP method of the request.
uri string
The URI to which the request will be sent, absolute or relative to BaseAddress.
responseObjectType Type
The type of the object expected in the response, or null if the response body is not read.

Returns

HttpRequestMessage
The new HttpRequestMessage.

Exceptions

ArgumentNullException
Thrown if method or uri is null.

Remarks

The request gets the headers of DefaultRequestHeaders, overridden by the headers of the active scopes. If neither sets an Accept header, it gets one with the media types that ContentFormatters can read into responseObjectType and into ResponseErrorType, or */* if responseObjectType is null.

The request gets the properties of the active scopes, and the following properties:

DecideOnRetryAsync(HttpRequestException, HttpRequestMessage, HttpRetryState, CancellationToken)

Decides whether to retry a request after a transient connection failure or a timeout.
protected virtual Task<HttpErrorHandlerResult> DecideOnRetryAsync(
	HttpRequestException error,
	HttpRequestMessage request,
	HttpRetryState retryState,
	CancellationToken cancellationToken)

Parameters

error HttpRequestException
The HttpRequestException encapsulating details of the encountered error during the HTTP request execution.
request HttpRequestMessage
The HttpRequestMessage that led to the failed response.
retryState HttpRetryState
The retry state of the call, shared by all its attempts.
cancellationToken CancellationToken
A token for canceling the operation.

Returns

Task<HttpErrorHandlerResult>
A task that resolves to an HttpErrorHandlerResult, indicating whether to retry the request or that the error is unrecoverable.

Exceptions

ArgumentNullException
Thrown if error, request or retryState is null.

Remarks

The base implementation retries as RetryPolicy decides. An override that creates its own HttpRequestErrorContext passes retryState to it, so that the retry sessions are kept across the attempts of the call.

See Also

DecideOnRetryAsync(HttpResponseException, HttpRequestMessage, HttpResponseMessage, HttpRetryState, CancellationToken)

Decides whether to retry a request after an error response.
protected virtual Task<HttpErrorHandlerResult> DecideOnRetryAsync(
	HttpResponseException error,
	HttpRequestMessage request,
	HttpResponseMessage response,
	HttpRetryState retryState,
	CancellationToken cancellationToken)

Parameters

error HttpResponseException
The HttpResponseException encapsulating details of the encountered error during the HTTP request execution.
request HttpRequestMessage
The HttpRequestMessage that led to the failed response.
response HttpResponseMessage
The received HttpResponseMessage indicating a failure.
retryState HttpRetryState
The retry state of the call, shared by all its attempts.
cancellationToken CancellationToken
A token for canceling the operation.

Returns

Task<HttpErrorHandlerResult>
A task that resolves to an HttpErrorHandlerResult, indicating whether to retry the request or that the error is unrecoverable.

Exceptions

ArgumentNullException
Thrown if error, request, response or retryState is null.

Remarks

The base implementation asks the handlers in ErrorHandlers that can handle the status code, in order, until one of them decides to retry. An override that creates its own HttpResponseErrorContext passes retryState to it, so that the retry sessions are kept across the attempts of the call.

See Also

DeserializeContentAsync(HttpResponseMessage, Type, CancellationToken)

Reads the body of a response into an object of the specified type.
protected virtual Task<object> DeserializeContentAsync(HttpResponseMessage response, Type objectType, CancellationToken cancellationToken)

Parameters

response HttpResponseMessage
The HttpResponseMessage to be read.
objectType Type
The type of object to which the response body is to be converted.
cancellationToken CancellationToken
A token for canceling the operation.

Returns

Task<object>
A task representing the asynchronous operation, with the deserialized response body as an object.

Exceptions

ArgumentNullException
Thrown if response or objectType is null.
HttpContentException
Thrown when the response body is empty, the content type is unsupported, or parsing the response fails.

Remarks

This method reads the content with the first formatter in ContentFormatters that can read its media type into objectType. If the formatter fails, the HttpContentException carries its exception as the inner exception.

See Also

DispatchAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)

Sends a request once, without retries.
protected virtual Task<HttpResponseMessage> DispatchAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)

Parameters

request HttpRequestMessage
The HttpRequestMessage to send.
completionOption HttpCompletionOption
When the operation completes: after the whole response body has been read, or as soon as the response headers have been read.
cancellationToken CancellationToken
A token for canceling the request.

Returns

Task<HttpResponseMessage>
A task that represents the asynchronous operation, with a result of the HttpResponseMessage received in response to the request.

Exceptions

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, or server certificate validation.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token, or if the timeout of the underlying HttpClient elapses.

Remarks

This method returns the response if its status code indicates success; for an error status code, it throws an HttpResponseException. It raises BeforeSendingRequest before sending and AfterReceivingResponse when the response arrives.

DispatchWithRetriesAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)

Sends a request, and retries it after a transient connection failure, a timeout, or an error response that a handler retries.
protected virtual Task<HttpResponseMessage> DispatchWithRetriesAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken = default)

Parameters

request HttpRequestMessage
The HttpRequestMessage to send.
completionOption HttpCompletionOption
When the operation completes: after the whole response body has been read, or as soon as the response headers have been read.
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task<HttpResponseMessage>
A task that represents the asynchronous operation, with a result of the HttpResponseMessage received in response to the request.

Exceptions

ArgumentNullException
Thrown if request 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, or server certificate validation.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token, or if the timeout of the underlying HttpClient elapses.

Remarks

After a transient connection failure or a timeout, the request is retried if RetryPolicy allows it. After an error response, it is retried if one of ErrorHandlers decides so. Otherwise, the failure is thrown.

See Also

Dispose()

Raises the Disposing event, then disposes the HttpClient of this client if the client owns it, or releases the reference of the client to a shared one.
public void Dispose()

Dispose(bool)

Raises the Disposing event and releases the HttpClient of this client, when called from Dispose().
protected virtual void Dispose(bool disposing)

Parameters

disposing bool
true when called from Dispose(); false when called from a finalizer.

Remarks

The HttpRestClient class has no finalizer, so this method is called with disposing set to false only by a finalizer that a derived class declares. A derived class that owns unmanaged resources must declare its own finalizer that calls this method with false.

OnAfterReceivingResponse(HttpResponseMessage)

Raises the AfterReceivingResponse event.
protected virtual void OnAfterReceivingResponse(HttpResponseMessage response)

Parameters

response HttpResponseMessage
The HTTP response message that was received.

Remarks

This method is called after a response is received and before the client processes it.

OnBeforeSendingRequest(HttpRequestMessage)

Raises the BeforeSendingRequest event.
protected virtual void OnBeforeSendingRequest(HttpRequestMessage request)

Parameters

request HttpRequestMessage
The HTTP request message that was created.

Remarks

This method is called before each attempt of a request is sent, including retries.

OnDisposing()

Raises the Disposing event.
protected virtual void OnDisposing()

Remarks

This method is called when the client is disposed, before it releases its HttpClient.

SendAsync(HttpMethod, string, HttpContent, HttpCompletionOption, CancellationToken)

Sends an asynchronous HTTP request with the specified method, URI, and payload, without processing the response body.
public virtual Task<HttpResponseMessage> SendAsync(
	HttpMethod method,
	string uri,
	HttpContent payload = null,
	HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead,
	CancellationToken cancellationToken = default)

Parameters

method HttpMethod
The HTTP method to use for the request.
uri string
The URI to which the request is sent.
payload HttpContent optional
The HTTP request payload content (optional).
completionOption HttpCompletionOption optional
When the operation completes: after the whole response body has been read (HttpCompletionOption.ResponseContentRead, the default), or as soon as the response headers have been read (HttpCompletionOption.ResponseHeadersRead).
cancellationToken CancellationToken optional
A token for canceling the request (optional).

Returns

Task<HttpResponseMessage>
A task that represents the asynchronous operation. The task result contains the response.

Exceptions

ArgumentNullException
Thrown if method or uri 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, or server certificate validation.
OperationCanceledException
Thrown if the operation is canceled via the cancellation token, or if the timeout of the underlying HttpClient elapses.

Remarks

With HttpCompletionOption.ResponseHeadersRead, the response body is not buffered: it is read from the network as the caller reads the response content, and the caller must dispose the response to release the connection. HttpClient.Timeout then covers only the time until the headers arrive, and a failure while the body is read is not retried.

SendAsync<T>(HttpMethod, string, HttpContent, CancellationToken)

Sends an asynchronous HTTP request with the specified method, URI, and payload, and returns the response body read as the specified type.
public virtual Task<T> SendAsync<T>(
	HttpMethod method,
	string uri,
	HttpContent payload = null,
	CancellationToken cancellationToken = default)

Type Parameters

T
The type of the response object.

Parameters

method HttpMethod
The HTTP method to use for the request.
uri string
The URI to which the request is sent.
payload HttpContent optional
The HTTP request payload content (optional).
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 method or uri 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, or server certificate validation.
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, or if the timeout of the underlying HttpClient elapses.

ToExceptionAsync(HttpResponseMessage, CancellationToken)

Creates the exception for an error response.
protected virtual Task<HttpResponseException> ToExceptionAsync(HttpResponseMessage response, CancellationToken cancellationToken)

Parameters

response HttpResponseMessage
The HTTP response message to convert.
cancellationToken CancellationToken
A token for canceling the operation.

Returns

Task<HttpResponseException>
A task that represents the asynchronous operation. The task result contains an HttpResponseException object that represents the error extracted from the response.

Exceptions

ArgumentNullException
Thrown if response is null.

Remarks

If ResponseErrorType is set, this method reads the response content into that type and stores the result in HttpResponseException.ResponseObject. If the result implements IHttpErrorResponse, it creates the exception; otherwise, or if the content cannot be read, the exception carries the status code and a default message.

See Also

Events

AfterReceivingResponse

Occurs when an HTTP response has been received.
public event EventHandler<HttpResponseMessageEventArgs> AfterReceivingResponse

Event Type

EventHandler<HttpResponseMessageEventArgs>

Remarks

The event is raised for every response, including error responses and responses that lead to a retry, before the client checks the status code or reads the content. Handlers can inspect or log the response.

For requests sent with HttpCompletionOption.ResponseHeadersRead, such as those of GetAsStreamAsync(this HttpRestClient, string, CancellationToken), GetToStreamAsync(this HttpRestClient, string, Stream, CancellationToken) and DownloadAsync(this HttpRestClient, HttpMethod, string, HttpContent, Func<HttpContentHeaders, Stream>, CancellationToken), the event is raised once the headers arrive and the body is not buffered. A subscriber that reads the response content consumes the body stream, which leaves nothing for the caller.

BeforeSendingRequest

Occurs before a request is sent.
public event EventHandler<HttpRequestMessageEventArgs> BeforeSendingRequest

Event Type

EventHandler<HttpRequestMessageEventArgs>

Remarks

The event is raised before every attempt of a request, including retries. Handlers can change the request, for example to add a header, and the changes are sent.

Disposing

Occurs when the client is disposed, before it releases its HttpClient.
public event EventHandler<EventArgs> Disposing

Event Type

EventHandler<EventArgs>

Extension Methods

DeleteAsync(this HttpRestClient, string, CancellationToken)Sends an asynchronous DELETE request to the specified URI without processing the response body.
DeleteAsync<T>(this HttpRestClient, string, CancellationToken)Sends an asynchronous DELETE request to the specified URI and returns the response body deserialized as the specified type.
DownloadAsync(this HttpRestClient, HttpMethod, string, HttpContent, Func<HttpContentHeaders, Stream>, CancellationToken)Sends an asynchronous HTTP request with the specified method, URI, and payload, returning the response content as a stream.
GetAsByteArrayAsync(this HttpRestClient, string, CancellationToken)Sends an asynchronous GET request to the specified URI and returns the response body as an array of bytes.
GetAsStreamAsync(this HttpRestClient, string, CancellationToken)Sends an asynchronous GET request to the specified URI and returns the response body as a Stream.
GetAsStringAsync(this HttpRestClient, string, CancellationToken)Sends an asynchronous GET request to the specified URI and returns the response body as a string.
GetAsync<T>(this HttpRestClient, string, CancellationToken)Sends an asynchronous GET request to the specified URI and returns the response body deserialized as the specified type.
GetToStreamAsync(this HttpRestClient, string, Stream, CancellationToken)Sends an asynchronous GET request to the specified URI and writes the response body into the provided Stream.
HeadAsync(this HttpRestClient, string, CancellationToken)Sends an asynchronous HEAD request to the specified URI and returns the response headers.
OptionsAsync(this HttpRestClient, string, CancellationToken)Sends an asynchronous OPTIONS request to the specified URI and returns the response headers.
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.
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.
PatchAsJsonAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PATCH request with JSON-formatted payload to the specified URI without processing the response body.
PatchAsJsonAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PATCH request with JSON-formatted payload to the specified URI and returns the response body deserialized as the specified type.
PatchAsJsonAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PATCH request with JSON-formatted payload to the specified URI without processing the response body.
PatchAsJsonAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PATCH request with JSON-formatted payload to the specified URI and returns the response body deserialized as the specified type.
PatchAsXmlAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PATCH request with XML-formatted payload to the specified URI without processing the response body.
PatchAsXmlAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PATCH request with XML-formatted payload to the specified URI and returns the response body deserialized as the specified type.
PatchAsync(this HttpRestClient, string, HttpContent, CancellationToken)Sends an asynchronous PATCH request to the specified URI without processing the response body.
PatchAsync<T>(this HttpRestClient, string, HttpContent, CancellationToken)Sends an asynchronous PATCH request to the specified URI and returns the response body deserialized as the specified type.
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.
PostAsFormAsync<T>(this HttpRestClient, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)Sends an asynchronous POST request with URL-encoded form content to the specified URI.
PostAsJsonAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous POST request with JSON-formatted payload to the specified URI without processing the response body.
PostAsJsonAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous POST request with JSON-formatted payload to the specified URI.
PostAsJsonAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous POST request with JSON-formatted payload to the specified URI without processing the response body.
PostAsJsonAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous POST request with JSON-formatted payload to the specified URI.
PostAsXmlAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous POST request with XML-formatted payload to the specified URI without processing the response body.
PostAsXmlAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous POST request with XML-formatted payload to the specified URI.
PostAsync(this HttpRestClient, string, HttpContent, CancellationToken)Sends an asynchronous POST request to the specified URI without processing the response body.
PostAsync<T>(this HttpRestClient, string, HttpContent, CancellationToken)Sends an asynchronous POST request to the specified URI and returns the response body deserialized as the specified type.
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.
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.
PutAsJsonAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PUT request with JSON-formatted payload to the specified URI without processing the response body.
PutAsJsonAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PUT request with JSON-formatted payload to the specified URI and returns the response body deserialized as the specified type.
PutAsJsonAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PUT request with JSON-formatted payload to the specified URI without processing the response body.
PutAsJsonAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PUT request with JSON-formatted payload to the specified URI and returns the response body deserialized as the specified type.
PutAsXmlAsync(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PUT request with XML-formatted payload to the specified URI without processing the response body.
PutAsXmlAsync<T>(this HttpRestClient, string, object, CancellationToken)Sends an asynchronous PUT request with XML-formatted payload to the specified URI and returns the response body deserialized as the specified type.
PutAsync(this HttpRestClient, string, HttpContent, CancellationToken)Sends an asynchronous PUT request to the specified URI without processing the response body.
PutAsync<T>(this HttpRestClient, string, HttpContent, CancellationToken)Sends an asynchronous PUT request to the specified URI and returns the response body deserialized as the specified type.
SendAsFormAsync(this HttpRestClient, HttpMethod, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)Sends an asynchronous request with URL-encoded form content to the specified URI without processing the response body.
SendAsFormAsync<T>(this HttpRestClient, HttpMethod, string, IEnumerable<KeyValuePair<string, string>>, CancellationToken)Sends an asynchronous request with URL-encoded form content to the specified URI.
SendAsJsonAsync(this HttpRestClient, HttpMethod, string, object, CancellationToken)Sends an asynchronous request with JSON-formatted payload to the specified URI without processing the response body.
SendAsJsonAsync<T>(this HttpRestClient, HttpMethod, string, object, CancellationToken)Sends an asynchronous request with JSON-formatted payload to the specified URI.
SendAsJsonAsync(this HttpRestClient, HttpMethod, string, object, CancellationToken)Sends an asynchronous request with JSON-formatted payload to the specified URI without processing the response body.
SendAsJsonAsync<T>(this HttpRestClient, HttpMethod, string, object, CancellationToken)Sends an asynchronous request with JSON-formatted payload to the specified URI.
SendAsXmlAsync(this HttpRestClient, HttpMethod, string, object, CancellationToken)Sends an asynchronous request with XML-formatted payload to the specified URI without processing the response body.
SendAsXmlAsync<T>(this HttpRestClient, HttpMethod, string, object, CancellationToken)Sends an asynchronous request with XML-formatted payload to the specified URI.
SendObjectAsync(this HttpRestClient, HttpMethod, string, object, string, CancellationToken)Sends an asynchronous request whose payload is written in the specified media type by a registered content formatter, without processing the response body.
SendObjectAsync(this HttpRestClient, HttpMethod, string, object, IHttpContentFormatter, CancellationToken)Sends an asynchronous request whose payload is written by the specified content formatter, without processing the response body.
SendObjectAsync<T>(this HttpRestClient, HttpMethod, string, object, string, CancellationToken)Sends an asynchronous request whose payload is written in the specified media type by a registered content formatter, and returns the response body deserialized as the specified type.
SendObjectAsync<T>(this HttpRestClient, HttpMethod, string, object, IHttpContentFormatter, CancellationToken)Sends an asynchronous request whose payload is written by the specified content formatter, and returns the response body deserialized as the specified type.
UseJson(this HttpRestClient, JsonSerializerOptions)Registers a JsonFormatter with the client, or updates the registered one.
UseNewtonsoftJson(this HttpRestClient, JsonSerializerSettings)Registers a NewtonsoftJsonFormatter with the client, or updates the registered one.
UseXml(this HttpRestClient, Action<XmlFormatter>)Registers an XmlFormatter with the client, or updates the registered one.
WithScope(this HttpRestClient)Starts a fluent definition of headers and request properties that apply to the requests of one operation.