-
Notifications
You must be signed in to change notification settings - Fork 1
Offline Request Queue
Opt-in per endpoint. A request sent while offline is archived and the caller gets
NetworkError.offlineQueued(id) immediately; the queue replays FIFO when connectivity returns.
config.offlineStore = FileOfflineStore() // persisted; survives launches
config.networkMonitor = PathNetworkMonitor()
struct SubmitOrder: Endpoint {
typealias Response = Order
var method: HTTPMethod { .post }
var offlineBehavior: OfflineBehavior { .queue(expiresAfter: 3600) }
}for await event in await client.offlineReplayEvents() {
switch event {
case .replayed(let id, let statusCode): ...
case .failed(let id, let error): ...
case .expired(let id): ...
}
}
await client.replayOfflineQueue() // also force a replay manuallyA replayed request is sent exactly as it was archived: it keeps the Authorization header it had,
with no token-refresh hop, so one that outlives its token replays as a 401 (delivered as .replayed
with that status). There is also no idempotency guard, so only queue requests that are safe to send
twice, or that the server de-duplicates.
Multipart bodies cannot be archived, so a multipart endpoint always fails fast instead of queueing.
A queued request is never dropped silently:
- A request whose re-send keeps failing at the transport level is dropped after 10 attempts, and
.failedis emitted each time. - A queued request that can no longer be rebuilt emits
.failedbefore it is dropped. -
FileOfflineStorelogs write failures, moves a file that is not valid JSON aside to<file>.corrupt, and leaves a file it cannot read untouched. Passlogger:to route those lines.
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