Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zunda-pixel/http-client
HTTPClient protocol for Swift
https://github.com/zunda-pixel/http-client
swift
Last synced: 22 days ago
JSON representation
HTTPClient protocol for Swift
- Host: GitHub
- URL: https://github.com/zunda-pixel/http-client
- Owner: zunda-pixel
- License: apache-2.0
- Created: 2024-08-10T15:03:09.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-10-29T07:17:57.000Z (2 months ago)
- Last Synced: 2024-12-02T18:00:57.089Z (about 1 month ago)
- Topics: swift
- Language: Swift
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTPClient
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fzunda-pixel%2Fhttp-client%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/zunda-pixel/http-client)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fzunda-pixel%2Fhttp-client%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/zunda-pixel/http-client)HTTPClient protocol for API Client Library
```swift
import HTTPClient
import HTTPClientFoundation
import Foundationlet api = GitHubAPI(
token: <#GITHUB_TOKEN#>,
httpClient: .urlSession(.shared)
)let user = api.user(id: <#user_id#>)
struct GitHubAPI {
let token: String
let httpClient: HTTPClientfunc user(id: String) async throws -> User {
let request = HTTPRequest(
method: .get,
url: url,
headerFields: [
.authorization: token
]
)
let (data, response) = try await httpClient.execut(request, body: nil)
let user = try JSONDecoder().decode(User.self, from: data)
return user
}
}
```