Advertisement
Intermediate .NET MAUI, Networking & APIs

How do you implement resilient HTTP calls (retries, timeouts) in MAUI?

Short answer

Wrap HttpClient with Polly via IHttpClientFactory's AddPolicyHandler to add retry with backoff, circuit breakers, and timeouts. This handles transient failures common on mobile networks without scattering try/catch and manual retry loops.

Save .NET MAUI mock interview
Advertisement
AModel answer
Wrap HttpClient with Polly via IHttpClientFactory's AddPolicyHandler to add retry with backoff, circuit breakers, and timeouts. This handles transient failures common on mobile networks without scattering try/catch and manual retry loops.
builder.Services.AddHttpClient<IApiClient, ApiClient>()
    .AddTransientHttpErrorPolicy(p =>
        p.WaitAndRetryAsync(3, r => TimeSpan.FromSeconds(Math.Pow(2, r))));
Real-world example
Flaky mobile connections recover automatically as failed requests retry with exponential backoff instead of surfacing errors immediately.
Likely follow-ups
  • What is a circuit breaker? | Where do you register Polly policies?
Related topics