SendAsync is the asynchronous method that processes an HTTP request and returns its response. In a custom handler, override it to add behavior before forwarding the request through the handler pipeline. section 33.4
A custom handler typically follows this sequence:
- Derive a handler from DelegatingHandler. section 33.4
- Override SendAsync with the request and cancellation-token parameters. section 33.4
- Modify the request, such as by adding an API key header. section 33.4
- Call base.SendAsync() to continue through the remaining handlers and eventually HttpClientHandler. section 33.5
- Inspect or modify the response after the downstream handlers finish. section 33.4
Adding an API key
An ApiKeyMessageHandler overrides SendAsync, adds an API-KEY header from injected settings, awaits the downstream response, and returns it. Register the handler with dependency injection, then attach it to a named or typed client with AddHttpMessageHandler<T>().

