-
Notifications
You must be signed in to change notification settings - Fork 1
Home
A modern, composable, protocol-oriented networking framework for Apple platforms.
Zero external dependencies · Swift 6 strict concurrency · 13 isolated actors · Single-flight 401 token refresh · SPKI SSL pinning
- Version: 1.1.0 (public API frozen; see Versioning-and-Roadmap)
-
Swift: 6.0 (
swift-tools-version:6.0, Swift 6 language mode) - Platforms: iOS 16+, macOS 13+, tvOS 16+, watchOS 9+, visionOS 1+
- Distribution: Swift Package Manager
- License: Source-available proprietary. Use it in your apps, including commercial ones; do not redistribute, publicly fork, or rebrand it. See FAQ-Licensing-and-Support.
- Repository: https://github.com/ihusnainalii/SwiftNetworkKit
- Docs site: https://swiftnetworkkit.vercel.app/
SwiftNetworkKit is a reusable client networking layer you drop into an app instead of hand-rolling
URLSession plumbing per project. It exists because every app re-implements the same things badly:
token refresh races, retry with backoff, certificate pinning, request cancellation, response
caching, redacted logging, and a test seam.
What it solves
- One typed
Endpointper API operation, decoded straight into your model. - A single
NetworkErrorat the public boundary; everyURLError,DecodingError, keychainOSStatus, and trust failure is mapped into it. - A
TokenManageractor that handles concurrent 401s with a single-flight refresh and request queueing, so ten simultaneous requests trigger exactly one refresh. - Drop-in certificate pinning where the app ships a
.cerand writes one line; the package owns theURLSessiondelegate. - A test double (
MockNetworkTransport) that ships in the library, so consumers never touch the network in unit tests.
Who should use it: app teams that want a consistent networking layer across projects, and anyone who needs pinning, OAuth, offline queueing, or automatic refresh without pulling in a large framework.
Design principles
-
Zero dependencies. Foundation, and platform frameworks behind
#if canImport. -
Composed, not a god object.
NetworkClientwires together small components (RequestBuilder,TokenManager,InterceptorChain,RequestQueue, caches, transport). - Protocol-oriented. Every collaborator is a protocol with a real adapter and a test double.
-
Modern Swift. ~95% async/await and actors under Swift 6 strict concurrency; Combine and
SwiftUI are optional
#if canImportadapters. - Everything is configuration. No hardcoded URLs, timeouts, or pins in the package.
| Topic | Page |
|---|---|
| Defining endpoints, request/response shape | Defining Endpoints |
| Auth strategies, token storage, automatic refresh, OAuth 2.0 | Authentication and Token Refresh |
| Certificate and public-key pinning, security posture | Security and Certificate Pinning |
Retry, backoff, jitter, Retry-After
|
Retry Policy |
| Request/response interceptors | Interceptors |
| Cancellation, deduplication, reachability, concurrency | Request Management |
| HTTP response caching | Caching |
| Persisted offline replay queue | Offline Request Queue |
| Multipart upload, file download, progress | Uploads Downloads and Progress |
| Pagination and parallel batch requests | Pagination and Batch |
| Combine publishers and SwiftUI helpers | Combine and SwiftUI |
The NetworkError model |
Error Handling |
| Environments, logging, metrics, tracing | Observability |
| Mock transport and other test doubles | Testing and Mocking |
| Recommended patterns + a full login-to-API example | Best Practices and a Complete Example |
| Known platform quirks, thread safety, performance notes | Platform Notes Thread Safety and Performance |
| Common questions, licensing, where to get support | FAQ Licensing and Support |
| Semantic versioning and the roadmap | Versioning and Roadmap |
-
CLI tour (
Sources/NetworkKitDemo/): a scripted run through every feature against the publicjsonplaceholder.typicode.comAPI.swift run NetworkKitDemo -
SwiftUI app (
Examples/SwiftUIDemo/): a standalone iOS app with a searchable paginated user list, a POST form, an image downloader with a live progress bar, and a Diagnostics screen with two narrated walkthroughs (401 → refresh → retry, and an account-switch showing cache isolation).
Open a GitHub Discussion for questions,
or a GitHub Issue for a bug, with
your OS/Xcode versions and a minimal reproduction. Report a security vulnerability privately per
SECURITY.md, never in a public issue.
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