ASP.NET Core Web API Interview Question #162
What is a typed HttpClient?
Testing, HttpClient, Integration Testing, Background Services & Deployment Senior Advanced
Quick Interview Answer
A typed HttpClient wraps HttpClient inside a dedicated service representing one external API. The class can expose domain-specific methods and keep URLs, serialization, headers, and error handling out of controllers.
Detailed Explanation
A typed HttpClient wraps HttpClient inside a dedicated service representing one external API. The class can expose domain-specific methods and keep URLs, serialization, headers, and error handling out of controllers.
Typed clients make external integrations easier to test and maintain.
Code Example
builder.Services.AddHttpClient<ICatalogClient, CatalogClient>(client =>
{
client.BaseAddress = new Uri("https://catalog.example.com/");
});
public sealed class CatalogClient(HttpClient http)
: ICatalogClient
{
// Domain-specific API methods
}