> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# HttpClient

> Extension methods for HttpClient from System.Net.Http

## Definition

**Assembly:** System.Net.Http.dll

**Namespace:** System.Net.Http

## Syntax

```csharp theme={"dark"}
System.Net.Http.HttpClient
```

## Summary

This type is defined in System.Net.Http.

## Remarks

See [Microsoft documentation](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient) for more information about the rest of the API.

## Methods

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> ExecuteTestRequest <Badge color="green">Extension</Badge>

<Note>Extension method from `System.Net.Http.Breakdance_WebApi_HttpClientExtensions`</Note>

Creates an [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) for the given configuration and executes it asynchronously through the HttpClient.

#### Syntax

```csharp theme={"dark"}
public static System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> ExecuteTestRequest(System.Net.Http.HttpClient httpClient, System.Net.Http.HttpMethod httpMethod, string host = "http://localhost/", string routePrefix = "api/tests/", string resource = null, string acceptHeader = "application/json", object payload = null, Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = null)
```

#### Parameters

| Name                     | Type                                     | Description                                                                                                                                                                 |
| ------------------------ | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `httpClient`             | `System.Net.Http.HttpClient`             | The [HttpClient](/breakdance/api-reference/System/Net/Http/HttpClient) instance to use.                                                                                     |
| `httpMethod`             | `System.Net.Http.HttpMethod`             | The [HttpMethod](https://learn.microsoft.com/dotnet/api/system.net.http.httpmethod) to use for the request.                                                                 |
| `host`                   | `string`                                 | The hostname to use for this request. Defaults to "[http://localhost](http://localhost)", only change it if that collides with other services running on the local machine. |
| `routePrefix`            | `string`                                 | The routePrefix corresponding to the route already mapped in MapRestierRoute or GetTestableConfiguration. Defaults to "api/test", only change it if absolutely necessary.   |
| `resource`               | `string`                                 | The resource on the API to be requested.                                                                                                                                    |
| `acceptHeader`           | `string`                                 | The inbound MIME types to accept. Defaults to "application/json".                                                                                                           |
| `payload`                | `object`                                 | -                                                                                                                                                                           |
| `jsonSerializerSettings` | `Newtonsoft.Json.JsonSerializerSettings` | -                                                                                                                                                                           |

#### Returns

Type: `System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>`
An [HttpResponseMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage) containing the results of the attempted request.

#### Examples

This sample shows the simplest way to create a testable [HttpClient](/breakdance/api-reference/System/Net/Http/HttpClient) and execute a test request, using MSTest and FluentAssertions.

```csharp theme={"dark"}
[TestClass]
 ApiTests
{
hod]
sync Task TestApi_Companies_ReturnsResults()
    {
httpClient = WebApiTestHelpers.GetTestableHttpClient();
result = await httpClient.ExecuteTestRequest(HttpMethods.Get, resource = "/Companies");
lt.Should().NotBeNull();
lt.StatusCode.Should().Be(HttpStatusCode.OK);
content = await result.Content.ReadAsStringAsync();
ent.Should().NotBeNullOrWhiteSpace();
    }
}
```
