-
Notifications
You must be signed in to change notification settings - Fork 1
Quick Start
Husnain Ali edited this page Sep 27, 2026
·
3 revisions
import SwiftNetworkKit
// 1. Configure once, inject everywhere.
let client = NetworkClient(
configuration: NetworkConfiguration(
baseURL: "https://api.example.com",
headers: ["Accept": "application/json"]
)
)
// 2. One type per API operation.
struct GetProfile: Endpoint {
typealias Response = User
var path: String { "/me" }
}
// 3. Call it.
let user: User = try await client.request(GetProfile())That's the whole minimal setup. Everything else, token refresh, pinning, caching, retry, offline
queueing, is opt-in through NetworkConfiguration or per-endpoint overrides. See
Defining Endpoints for the full Endpoint shape, or jump straight to
Authentication and Token Refresh if you need auth right away.
let user: User = try await client.request(GetProfile())
// convenience helpers
let raw: Data = try await client.data(for: GetProfile())
let text: String = try await client.string(for: GetREADME())
try await client.send(DeleteAccount()) // ignores the bodyclient.request(GetProfile()) { (result: Result<User, NetworkError>) in
switch result {
case .success(let user): ...
case .failure(let error): ...
}
}client.publisher(for: GetProfile())
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { ... }, receiveValue: { user in ... })
.store(in: &cancellables)See Combine and SwiftUI for the rest of the reactive surface.
let id = RequestID()
async let profile = client.request(GetProfile(), id: id)
// later, from anywhere:
await client.cancel(id)See Request Management for cancellation, deduplication, and concurrency limits.
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