kean / Get

Web API client built using async/await
MIT License
943 stars 75 forks source link

Get 3.0 #75

Open kean opened 1 year ago

kean commented 1 year ago

Prototype of the new Sendable-compliant APIs to address new Xcode 14.3 warnings and make the framework easier to user.

private struct User: Decodable {}

func usage() async throws {
    let client = APIClient(baseURL: nil)

    let dataTask = await client.dataTask(with: Request<User>(path: "/user"))

    if #available(iOS 15, *) {
        for await progress in dataTask.progress.values {
            print(progress)
        }
    }

    let response = try await dataTask.response.value
    let data = try await dataTask.data
    let string = try await dataTask.string
}