HttpClientExtensions Class
Definition
- Namespace
- Codebelt.Extensions.Xunit.Hosting.AspNetCore
- Assemblies
- Codebelt.Extensions.Xunit.Hosting.AspNetCore.dll
Provides extension methods for the HttpClient class.
public static class HttpClientExtensions
- Inheritance
-
HttpClientExtensions
Examples
The following example sends an HTTP request using the ToHttpResponseMessageAsync extension on an HttpClient. By default it performs a GET request to the root URL ("/"), or you can supply a custom response factory delegate. This method is designed to work with test host fixtures that provide a pre-configured HttpClient.
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Codebelt.Extensions.Xunit.Hosting.AspNetCore;
namespace WebFixtureTests;
public class HttpClientExample
{
public async Task DemonstrateAsync(HttpClient client)
{
var response = await client.ToHttpResponseMessageAsync().ConfigureAwait(false);
Console.WriteLine(response.StatusCode);
}
}
Methods
| Name | Description |
|---|---|
| ToHttpResponseMessageAsync(HttpClient, Func<HttpClient, Task<HttpResponseMessage>>) | Provides a convenient way to return a HttpResponseMessage from a HttpClient using the specified |