-
Notifications
You must be signed in to change notification settings - Fork 1
Retry Policy
Husnain Ali edited this page Sep 27, 2026
·
3 revisions
config.retry = .default // 3 attempts, exponential backoff + full jitter, respects Retry-After
config.retry = .none // 1 attempt
config.retry = .aggressive // more attempts, wider backoff
config.retry = RetryPolicy(
maxAttempts: 4,
retryableStatusCodes: [408, 429, 500, 502, 503, 504],
backoff: .exponential(base: 0.5, multiplier: 2, max: 30),
jitter: .full,
respectRetryAfter: true,
maxRetryAfterDelay: 120,
retryNonIdempotent: false
)-
Idempotency-aware.
GET/HEAD/PUT/DELETEretry by default;POST/PATCHdo not, unlessretryNonIdempotent: trueor the endpoint opts in. -
Rate limiting.
429and503with aRetry-Afterheader wait exactly that long (capped atmaxRetryAfterDelay), overriding the backoff curve. TheRetry-AfterHTTP-date form is parsed with one shared formatter, not one per request. - Per-endpoint override:
struct SubmitOrder: Endpoint {
typealias Response = Order
var method: HTTPMethod { .post }
var retryPolicy: RetryPolicy? { RetryPolicy(retryNonIdempotent: true) } // this POST is safe to repeat
}Timing goes through a NetworkClock port, so retry logic is unit-tested with TestClock and no
real waiting. See Testing and Mocking.
Best practice: do not blindly enable retryNonIdempotent; make each POST opt in only when it
is genuinely safe to repeat.
SwiftNetworkKit is source-available proprietary software (not open source). See FAQ Licensing and Support. Repo: https://github.com/ihusnainalii/SwiftNetworkKit · Docs: https://swiftnetworkkit.vercel.app/
Getting started
Guides
- Defining Endpoints
- Authentication and Token Refresh
- Security and Certificate Pinning
- Retry Policy
- Interceptors
- Request Management
- Caching
- Offline Request Queue
- Uploads Downloads and Progress
- Pagination and Batch
- Combine and SwiftUI
- Error Handling
- Observability
- Testing and Mocking
- Best Practices and a Complete Example
- Platform Notes, Thread Safety and Performance
Reference