
Kite is named after the kite bird, known for its lightness, speed, and agile flight. This Swift Package aims to embody those qualities—offering a lightweight, fast, and flexible networking layer that soars across Apple platforms.
- Swift Concurrency (async/await): Easily manage asynchronous networking operations.
- Lightweight API Client: A simple APIClient class lets you execute requests that conform to HTTPRequestProtocol or DeserializeableRequest.
- JSON & XML Deserialization: Built-in JSONDeserializer and XMLDeserializer types for decoding server responses.
This project is considered production-ready. Contributions—whether pull requests, questions, or suggestions—are always welcome! 😃
You can use Xcode SPM GUI: File -> Swift Packages -> Add Package Dependency -> Pick "Up to Next Major Version 3.0.0".
Or add the following to your Package.swift
file:
.package(url: "https://github.com/artemkalinovsky/Kite.git", from: "3.0.0")
Then specify "Kite" as a dependency of the target in which you wish to use Kite.
Here's an example Package.swift
:
// swift-tools-version:6.0
import PackageDescription
let package = Package(
name: "MyPackage",
products: [
.library(
name: "MyPackage",
targets: ["MyPackage"]),
],
dependencies: [
.package(url: "https://github.com/artemkalinovsky/Kite.git", from: "3.0.0")
],
targets: [
.target(
name: "MyPackage",
dependencies: ["Kite"])
]
)
Let's suppose we want to fetch a list of users from JSON and the response looks like this:
{
"results":[
{
"name":{
"first":"brad",
"last":"gibson"
},
"email":"brad.gibson@example.com"
}
]
}
- Create
APIClient
:
let apiClient = APIClient()
- Create the Response Model:
struct User: Decodable {
struct Name: Decodable {
let first: String
let last: String
}
let name: Name
let email: String
}
- Create a Request with Endpoint Path and Desired Response Deserializer:
import Foundation
import Kite
struct FetchRandomUsersRequest: DeserializeableRequestProtocol {
var baseURL: URL { URL(string: "https://randomuser.me")! }
var path: String {"api"}
var deserializer: ResponseDataDeserializer<[User]> {
JSONDeserializer<User>.collectionDeserializer(keyPath: "results")
}
}
Task {
let (users, urlResponse) = try await apiClient.execute(request: FetchRandomUsersRequest())
}
Voilà!🧑🎨
- @0111b for JSONDecoder-Keypath
- @drmohundro for SWXMLHash
Kite is released under an MIT license. See LICENCE for more information.