Calling Other Services with HttpClient
Talk it through out loud with your AI coach.
The problem
- medium
- Pro
A .NET service creates a new HttpClient inside a using block for every outgoing call, and under load it starts failing with socket errors. A colleague suggests one static HttpClient instead. Explain what's going wrong and the best way to make outgoing HTTP calls.
What a strong answer covers
- Why short-lived clients exhaust resources.
- The hidden downside of a single client that never changes.
- The framework's answer that balances both problems.
- Protecting the caller when the other service misbehaves.
Common mistake: Wrapping HttpClient in a using block because it implements IDisposable, as you would a file.
Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.
Practise it out loud