liveBook · Manning

Typed client

As explained in ASP.NET Core in Action, 3e

A typed client is an application-specific wrapper around HttpClient that exposes remote-service operations through a strongly typed class.

A typed client is a dedicated service class that wraps an HttpClient and exposes clear operations for a remote API. It keeps URL paths, HTTP verbs, response handling, and other HTTP mechanics out of consuming code. section 33.2.3

ExchangeRatesClient

An ExchangeRatesClient accepts HttpClient through its constructor and exposes GetLatestRates(). The method requests the latest rates, checks for a successful response, and returns the response content. An endpoint can inject the client and call only that method. section 33.2.3

Register and configure the client with IHttpClientFactory:

  • Inject the typed client into consuming services or endpoints instead of constructing HTTP requests there. section 33.2.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains constructor injection, request encapsulation, registration, and consumption, while broader handler-pipeline behavior is treated separately.
Examples
Uses an ExchangeRatesClient that retrieves latest exchange rates through a configured HTTP client.
What it assumes
Assumes familiarity with C# classes and HttpClient while demonstrating the client abstraction and its dependency-injection setup.
What you can do after
Build it from scratch by defining a client class, registering it with AddHttpClient, and injecting it into consumers.
How it connects
Connects HttpClient and IHttpClientFactory with dependency injection, named clients, custom HTTP message handlers, and Polly resilience policies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.