TinyNetworking is a lightweight Swift networking SDK for Apple platforms. It provides a small async/await HTTP layer, optional OAuth authorization helpers, and an OpenAPI transport that plugs into generated clients.
- Native Swift Concurrency API
- Small request and response models with sensible defaults
- Base URL and default header configuration
- Multipart file upload support with progress callbacks
- SSL certificate and public key pinning support
- OAuth authorization flow built on
ASWebAuthenticationSession - OpenAPI transport for generated Swift clients
- Swift Package Manager support
- Swift 6.1+
- iOS 15+
- tvOS 13+
- watchOS 6+
Add the package in Xcode or declare it in Package.swift:
dependencies: [
.package(
name: "TinyNetworking",
url: "https://github.com/Commencis/TinyNetworking.git",
from: "1.0.0"
)
]Choose the product you need:
TinyNetworking: core HTTP clientTinyNetworkingAuth: OAuth and web authentication helpersTinyNetworkingOpenAPI: transport adapter for Swift OpenAPI generated clients
Example target dependency:
.target(
name: "AppFeature",
dependencies: [
.product(name: "TinyNetworking", package: "TinyNetworking")
]
)import Foundation
import TinyNetworking
struct User: Decodable {
let id: Int
let name: String
}
let manager = URLSessionManager(
sessionConfiguration: SessionConfiguration(
baseURL: URL(string: "https://api.example.com")!,
headers: [
HTTPHeader.Key.contentType: HTTPHeader.Value.ContentType.json,
"Accept": "application/json"
]
)
)
let request = Request(
endpoint: "/users/42",
method: .get
)
let response = try await manager.send(request: request)
let user: User? = try response.responseModel()Request supports:
- raw
Databodies - JSON dictionary bodies
- URL-encoded form bodies
- any
Encodablemodel - multipart file uploads
struct CreatePostRequest: Encodable {
let title: String
let body: String
}
let request = Request(
endpoint: "/posts",
method: .post,
headers: [
HTTPHeader.Key.contentType: HTTPHeader.Value.ContentType.json
],
body: CreatePostRequest(title: "Hello", body: "TinyNetworking")
)Response exposes the raw payload as well as convenience decoding helpers:
let response = try await manager.send(request: request)
print(response.statusCode ?? 0)
print(response.responseString ?? "")
let model: User? = try response.responseModel()
let json = response.responseJSONlet file = FileUploadData(
fileName: "avatar.jpg",
parameterName: "file",
data: imageData
)
let uploadRequest = Request(
endpoint: "/uploads",
method: .post,
headers: [
"Accept": "application/json"
],
fileParameters: [file]
)
let response = try await manager.send(request: uploadRequest) { progress in
print("Uploaded: \(progress.totalBytesSent) / \(progress.totalBytesExpectedToSend)")
}URLSessionManager supports three server trust modes:
- default platform validation
- pinned certificate validation
- pinned public key hash validation
Examples:
manager.setPinnedCertificates(["api-example"])
manager.setPinnedPublicKeyHashes(["base64EncodedSPKIHash"])
manager.setAllowInvalidCertificates(true)Use setAllowInvalidCertificates(true) only in controlled development environments.
Import TinyNetworkingAuth when you need an authorization flow based on ASWebAuthenticationSession and PKCE.
import Foundation
import TinyNetworkingAuth
struct TokenResponse: Decodable, Sendable {
let accessToken: String
let refreshToken: String?
let expiresIn: Int?
}
@MainActor
func signIn() async throws -> TokenResponse {
let configuration = AuthorizationConfiguration(
authorizeURL: URL(string: "https://auth.example.com/oauth/authorize")!,
accessTokenURL: URL(string: "https://auth.example.com/oauth/token")!,
clientId: "ios-app",
redirectUri: "myapp://oauth/callback",
callbackURLScheme: "myapp",
scope: ["openid", "profile"],
codeChallengeMethod: .s256,
prefersEphemeral: true
)
let webSession = WebAuthenticationSession(
anchorProvider: DefaultPresentationAnchorProvider()
)
let manager = OAuthManager(
configuration: configuration,
webAuthSession: webSession
)
return try await manager.signIn()
}Import TinyNetworkingOpenAPI to use TinyNetworking as the transport for a generated Swift OpenAPI client.
import Foundation
import TinyNetworking
import TinyNetworkingOpenAPI
let manager = URLSessionManager(
sessionConfiguration: SessionConfiguration(
baseURL: URL(string: "https://api.example.com")!
)
)
let transport = manager.openAPITransport
// Example with a generated client:
// let client = Client(serverURL: URL(string: "https://api.example.com")!, transport: transport)TinyNetworking/Sources: core networking productTinyNetworking/Auth: OAuth productTinyNetworking/OpenAPI: OpenAPI transport product- ReleaseNotes.md: release history
- LICENSE: Apache 2.0
TinyNetworking is distributed under the Apache License 2.0. See LICENSE for details.