Skip to content

A Swift 6 networking library with async/await, JSON/XML deserialization ๐Ÿš€, and OAuth2 integration ๐Ÿ”, supporting iOS/macOS/tvOS/watchOS/visionOS/DriverKit!

License

Notifications You must be signed in to change notification settings

artemkalinovsky/Kite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

swift workflow Swift 6 macOS iOS tvOS watchOS driverKit visionOS

Kite

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.

Features:

  • 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.

Project Status

This project is considered production-ready. Contributionsโ€”whether pull requests, questions, or suggestionsโ€”are always welcome! ๐Ÿ˜ƒ

Installation ๐Ÿ“ฆ

  • Swift Package Manager

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"])
    ]
)

Usage ๐Ÿง‘โ€๐Ÿ’ป

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"
      }
   ]
}
  • Setup

  1. Create APIClient :
    let apiClient = APIClient()
  1. Create the Response Model:
struct User: Decodable {
    struct Name: Decodable {
        let first: String
        let last: String
    }
    
    let name: Name
    let email: String
}
  1. 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")
    }
}
  • Perform the Request

Task {
    let (users, urlResponse) = try await apiClient.execute(request: FetchRandomUsersRequest())
}

Voilร !๐Ÿง‘โ€๐ŸŽจ

Apps using Kite

Credits ๐Ÿ‘

License ๐Ÿ“„

Kite is released under an MIT license. See LICENCE for more information.

About

A Swift 6 networking library with async/await, JSON/XML deserialization ๐Ÿš€, and OAuth2 integration ๐Ÿ”, supporting iOS/macOS/tvOS/watchOS/visionOS/DriverKit!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages