Back to results for “.NET CLI”
.NET MAUI › Networking & APIs

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

Intermediate

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.

Common follow-ups: What is a circuit breaker? | Where do you register Polly policies?