Client
Description
Class for making HTTP requests with built-in resilience, connection reuse and automatic retries. Uses HttpClient and Polly under the hood.
Features
- All HTTP methods: GET, POST, PUT, DELETE, HEAD, OPTIONS — sync and async variants
- Connection reuse: underlying
HttpClientcached per host, port, timeout, scheme, SSL and decompression settings — eliminates socket exhaustion - Retry policy: configurable, see Behavior
- Circuit breaker [Pro Tier]: stops requests for 7 seconds after 25 consecutive errors on the same host + path
- Fluent API: call directly on any string URL via extension methods
Behavior
Defaults are read from appsettings and can be overridden per instance in the constructor. A new Client instance does not necessarily create a new underlying HttpClient — it reuses one from cache if scheme, host, port, timeout, SSL and decompression settings match.
Retry policy disabled (default):
- Always retries once on 502, 504 for GET, POST and file requests
- Always retries once if remote host forcibly closes the connection
- These base retries cannot be disabled
Retry policy enabled:
- All of the above, plus retries on 401, 404, 500 for GET/POST and file requests
- Up to two retries if response is null (timeout)
- 666ms delay between retries
useRetryPolicy: false (default)
- Retries once on 502, 504 (GET, POST, file requests)
useRetryPolicy: true
- Same as
false, plus:- Retries one extra time on 502, 504 (GET, POST)
- Retries twice if response is
null(timeout/no response) - Retries once on:
- 401 for GET, POST
- 404 for GET
- 500 for GET, POST
- 404, 500, 502, 504 for file requests
- 404, 502, 504 for OPTION, PATCH, HEAD, CONNECT, TRACE**
Caveats
DELETEandPUTare never retried- 502 and 504 on GET, POST or file requests always retry at least once — set
retryTimeout: 0in appsettings to disable throwOnUnsuccessfuldefaults tofalse— errors are logged as warnings, not thrownClientCertificatemust include a private key or an exception is thrown
Tip
Inherit Client to build typed integration clients — share base URL, headers, and auth logic across all methods in one place.
AppSettings
View all appsettings here