https://github.com/zunda-pixel/http-client
HTTPClient protocol for Swift
https://github.com/zunda-pixel/http-client
swift
Last synced: about 1 year 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 (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T07:17:57.000Z (over 1 year ago)
- Last Synced: 2025-03-16T07:17:55.797Z (about 1 year 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://swiftpackageindex.com/zunda-pixel/http-client)
[](https://swiftpackageindex.com/zunda-pixel/http-client)
HTTPClient protocol for API Client Library
```swift
import HTTPClient
import HTTPClientFoundation
import Foundation
let api = GitHubAPI(
token: <#GITHUB_TOKEN#>,
httpClient: .urlSession(.shared)
)
let user = api.user(id: <#user_id#>)
struct GitHubAPI {
let token: String
let httpClient: HTTPClient
func 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
}
}
```