HttpRestClient Class
- Namespace
- Kampute.HttpClient
- Assembly
- Kampute.HttpClient.dll
Definition
public class HttpRestClient : IDisposable- Inheritance
- object
- HttpRestClient
- Implements
Remarks
Constructors
HttpRestClient()
public HttpRestClient()Remarks
HttpRestClient(SharedDisposable<HttpClient>.Reference)
public HttpRestClient(SharedDisposable<HttpClient>.Reference httpClientReference)Parameters
httpClientReferenceSharedDisposable<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
httpClientReferenceisnull.
HttpRestClient(HttpClient, bool)
public HttpRestClient(HttpClient httpClient, bool disposeClient = true)Parameters
httpClientHttpClient- The HttpClient that sends the requests of this client.
disposeClientbool optionaltrueto disposehttpClientwhen this client is disposed;falseto leave it to its owner. The default istrue.
Exceptions
- ArgumentNullException
- Thrown if
httpClientisnull.
Properties
BaseAddress
public Uri BaseAddress { get; set; }Property Value
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
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
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
lock (client.DefaultRequestHeaders)
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthSchemes.Bearer, accessToken);
}ErrorHandlers
public HttpErrorHandlerCollection ErrorHandlers { get; }Property Value
- HttpErrorHandlerCollection
- The error handlers of this client.
Remarks
ResponseErrorType
public Type ResponseErrorType { get; set; }Property Value
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
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
nullrestores 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
client.RetryPolicy = RetryStrategies.Exponential(TimeSpan.FromSeconds(1)).WithMaxRetries(5).ToHttpRetryPolicy();Methods
BeginHeaderScope(IEnumerable<KeyValuePair<string, string>>)
public virtual IDisposable BeginHeaderScope(IEnumerable<KeyValuePair<string, string>> headers)Parameters
headersIEnumerable<KeyValuePair<string, string>>- The headers to set, or, with a
nullvalue, to remove.
Returns
- IDisposable
- An IDisposable that ends the scope when it is disposed.
Exceptions
- ArgumentNullException
- Thrown if
headersisnull.
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>>)
public virtual IDisposable BeginPropertyScope(IEnumerable<KeyValuePair<string, object>> properties)Parameters
propertiesIEnumerable<KeyValuePair<string, object>>- The properties to set, or, with a
nullvalue, to remove.
Returns
- IDisposable
- An IDisposable that ends the scope when it is disposed.
Exceptions
- ArgumentNullException
- Thrown if
propertiesisnull.
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)
protected virtual HttpRequestMessage CreateHttpRequest(HttpMethod method, string uri, Type responseObjectType)Parameters
methodHttpMethod- The HTTP method of the request.
uristring- The URI to which the request will be sent, absolute or relative to BaseAddress.
responseObjectTypeType- The type of the object expected in the response, or
nullif the response body is not read.
Returns
- HttpRequestMessage
- The new HttpRequestMessage.
Exceptions
- ArgumentNullException
- Thrown if
methodoruriisnull.
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:
- HttpRequestMessagePropertyKeys.TransactionId– A unique identifier (Guid) of the request, which the clones made for its retries keep, so that the attempts of a call can be correlated in logs.
- HttpRequestMessagePropertyKeys.ResponseObjectType– The .NET type (Type) expected in the response, if any.
DecideOnRetryAsync(HttpRequestException, HttpRequestMessage, HttpRetryState, CancellationToken)
protected virtual Task<HttpErrorHandlerResult> DecideOnRetryAsync(
HttpRequestException error,
HttpRequestMessage request,
HttpRetryState retryState,
CancellationToken cancellationToken)Parameters
errorHttpRequestException- The HttpRequestException encapsulating details of the encountered error during the HTTP request execution.
requestHttpRequestMessage- The HttpRequestMessage that led to the failed response.
retryStateHttpRetryState- The retry state of the call, shared by all its attempts.
cancellationTokenCancellationToken- 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,requestorretryStateisnull.
Remarks
retryState to it, so that the retry sessions are kept across the attempts of the call.See Also
DecideOnRetryAsync(HttpResponseException, HttpRequestMessage, HttpResponseMessage, HttpRetryState, CancellationToken)
protected virtual Task<HttpErrorHandlerResult> DecideOnRetryAsync(
HttpResponseException error,
HttpRequestMessage request,
HttpResponseMessage response,
HttpRetryState retryState,
CancellationToken cancellationToken)Parameters
errorHttpResponseException- The HttpResponseException encapsulating details of the encountered error during the HTTP request execution.
requestHttpRequestMessage- The HttpRequestMessage that led to the failed response.
responseHttpResponseMessage- The received HttpResponseMessage indicating a failure.
retryStateHttpRetryState- The retry state of the call, shared by all its attempts.
cancellationTokenCancellationToken- 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,responseorretryStateisnull.
Remarks
retryState to it, so that the retry sessions are kept across the attempts of the call.See Also
DeserializeContentAsync(HttpResponseMessage, Type, CancellationToken)
protected virtual Task<object> DeserializeContentAsync(HttpResponseMessage response, Type objectType, CancellationToken cancellationToken)Parameters
responseHttpResponseMessage- The HttpResponseMessage to be read.
objectTypeType- The type of object to which the response body is to be converted.
cancellationTokenCancellationToken- 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
responseorobjectTypeisnull. - HttpContentException
- Thrown when the response body is empty, the content type is unsupported, or parsing the response fails.
Remarks
objectType. If the formatter fails, the HttpContentException carries its exception as the inner exception.See Also
DispatchAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)
protected virtual Task<HttpResponseMessage> DispatchAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)Parameters
requestHttpRequestMessage- The HttpRequestMessage to send.
completionOptionHttpCompletionOption- When the operation completes: after the whole response body has been read, or as soon as the response headers have been read.
cancellationTokenCancellationToken- 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
DispatchWithRetriesAsync(HttpRequestMessage, HttpCompletionOption, CancellationToken)
protected virtual Task<HttpResponseMessage> DispatchWithRetriesAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken = default)Parameters
requestHttpRequestMessage- The HttpRequestMessage to send.
completionOptionHttpCompletionOption- When the operation completes: after the whole response body has been read, or as soon as the response headers have been read.
cancellationTokenCancellationToken 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
requestisnull. - 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
See Also
Dispose()
public void Dispose()Dispose(bool)
protected virtual void Dispose(bool disposing)Parameters
Remarks
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)
protected virtual void OnAfterReceivingResponse(HttpResponseMessage response)Parameters
responseHttpResponseMessage- The HTTP response message that was received.
Remarks
OnBeforeSendingRequest(HttpRequestMessage)
protected virtual void OnBeforeSendingRequest(HttpRequestMessage request)Parameters
requestHttpRequestMessage- The HTTP request message that was created.
Remarks
OnDisposing()
protected virtual void OnDisposing()Remarks
SendAsync(HttpMethod, string, HttpContent, HttpCompletionOption, CancellationToken)
public virtual Task<HttpResponseMessage> SendAsync(
HttpMethod method,
string uri,
HttpContent payload = null,
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead,
CancellationToken cancellationToken = default)Parameters
methodHttpMethod- The HTTP method to use for the request.
uristring- The URI to which the request is sent.
payloadHttpContent optional- The HTTP request payload content (optional).
completionOptionHttpCompletionOption 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).
cancellationTokenCancellationToken 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
methodoruriisnull. - 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
SendAsync<T>(HttpMethod, string, HttpContent, CancellationToken)
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
methodHttpMethod- The HTTP method to use for the request.
uristring- The URI to which the request is sent.
payloadHttpContent optional- The HTTP request payload content (optional).
cancellationTokenCancellationToken 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
methodoruriisnull. - 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)
protected virtual Task<HttpResponseException> ToExceptionAsync(HttpResponseMessage response, CancellationToken cancellationToken)Parameters
responseHttpResponseMessage- The HTTP response message to convert.
cancellationTokenCancellationToken- 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
responseisnull.
Remarks
See Also
Events
AfterReceivingResponse
public event EventHandler<HttpResponseMessageEventArgs> AfterReceivingResponseEvent Type
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
public event EventHandler<HttpRequestMessageEventArgs> BeforeSendingRequestEvent Type
Remarks
Disposing
public event EventHandler<EventArgs> DisposingEvent Type
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. |

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 noAcceptheader, 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.