Class HttpClientExtensions
- Assembly
- Codebelt.Extensions.Xunit.Hosting.AspNetCore.dll
Provides extension methods for the System.Net.Http.HttpClient class.
public static class HttpClientExtensions
- Inheritance
-
ObjectHttpClientExtensions
Methods
ToHttpResponseMessageAsync(HttpClient, Func<HttpClient, Task<HttpResponseMessage>>)
Provides a convenient way to return a System.Net.Http.HttpResponseMessage from a System.Net.Http.HttpClient using the specified responseFactory
.
public static async Task<HttpResponseMessage> ToHttpResponseMessageAsync(this HttpClient client, Func<HttpClient, Task<HttpResponseMessage>> responseFactory = null)
Parameters
client
HttpClientThe System.Net.Http.HttpClient to extend.
responseFactory
Func<HttpClient, Task<HttpResponseMessage>>The function delegate that creates a System.Net.Http.HttpResponseMessage from the System.Net.Http.HttpClient. Default is a GET request to the root URL ("/").
Returns
- Task<HttpResponseMessage>
A System.Threading.Tasks.Task that represents the asynchronous operation. The task result contains the System.Net.Http.HttpResponseMessage generated by the
responseFactory
.
Remarks
Designed to be used in conjunction with RunAsync(Action<IServiceCollection>, Action<IApplicationBuilder>, Action<IHostBuilder>, Func<HttpClient, Task<HttpResponseMessage>>) and RunWithHostBuilderContextAsync(Action<HostBuilderContext, IServiceCollection>, Action<HostBuilderContext, IApplicationBuilder>, Action<IHostBuilder>, Func<HttpClient, Task<HttpResponseMessage>>).
Exceptions
- System.ArgumentNullException
client
cannot be null.