Swiftpack.co - tevelee/AsyncHTTP as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tevelee.
tevelee/AsyncHTTP 1.1.0
Swift networking with async/await
⭐️ 7
🕓 17 weeks ago
iOS macOS watchOS tvOS macCatalyst
.package(url: "https://github.com/tevelee/AsyncHTTP.git", from: "1.1.0")


Generic networking library written using Swift async/await

let request = try HTTPRequest().configured { request in
    request.path = "endpoint"
    request.method = .post
    request.body = try .json(["a": "b"])
    request[header: .accept] = .application.json.appending(.characterSet, value: .utf8)
    request[header: .authorization] = .bearer(token: "token")
    request.addQueryParameter(name: "q", value: "search")
    request.serverEnvironment = .production
    request.timeout = 60
    request.retryStrategy = .immediately(maximumNumberOfAttempts: 3)

let loader: some HTTPLoader = URLSession.shared.httpLoader()
    .applyTimeout(default: 30)
    .throttle(maximumNumberOfRequests: 2)

let response: HTTPResponse = try await loader.load(request)
let body: MyResponseStruct = try response.jsonBody()



Stars: 7
Last commit: 17 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

17 weeks ago
  • Adopted primary associated types: allows opaque type constraints such as some Loader<URLRequest, HTTPURLResponse>
  • Advanced rethrows mechanism: load() only throws if there is an explicitly throwing operator in the loader chain

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics