Build a resilient C# HTTP client
8 steps · about 4 h 35 min · Intermediate
- Plan connection reuse (reference, Microsoft Learn, 35 min)
Avoid socket exhaustion and stale DNS by choosing an appropriate client lifetime.
- Keep I/O asynchronous (reference, Microsoft Learn, 35 min)
Compose tasks without blocking threads or hiding failures in fire-and-forget calls.
- Propagate cancellation (reference, Microsoft Learn, 30 min)
Let callers stop requests and related parsing work through one explicit signal.
- Set a request time budget (reference, Microsoft Learn, 25 min)
Bound total waiting time and distinguish timeout policy from user cancellation.
- Validate HTTP responses (reference, Microsoft Learn, 35 min)
Handle status, headers and content explicitly instead of assuming every completed request succeeded.
- Retry only transient failures (guide, Microsoft Learn, 40 min)
Use bounded delays and avoid retrying unsafe operations or permanent client errors.
- Create a typed client (reference, Microsoft Learn, 35 min)
Centralise configuration and dependencies behind a small domain-focused interface.
- Test through a message handler (reference, Microsoft Learn, 40 min)
Simulate response sequences and delays without depending on a live external service.