Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tevelee/asynchttp
Swift networking with async/await
https://github.com/tevelee/asynchttp
async-await http networking swift
Last synced: 16 days ago
JSON representation
Swift networking with async/await
- Host: GitHub
- URL: https://github.com/tevelee/asynchttp
- Owner: tevelee
- License: mit
- Created: 2021-11-30T15:04:47.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-02T14:14:35.000Z (over 1 year ago)
- Last Synced: 2024-03-19T11:00:33.606Z (8 months ago)
- Topics: async-await, http, networking, swift
- Language: Swift
- Homepage: https://tevelee.github.io/AsyncHTTP/documentation/asynchttp
- Size: 6.33 MB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# AsyncHTTP
Generic networking library written using Swift async/await
```swift
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()
.applyServerEnvironment()
.applyTimeout(default: 30)
.applyRetryStrategy()
.deduplicate()
.throttle(maximumNumberOfRequests: 2)let response: HTTPResponse = try await loader.load(request)
let body: MyResponseStruct = try response.jsonBody()print(request.formatted())
print(response.formatted())
```