https://github.com/cpageler93/api-client
Easy HTTP Client for Swift
https://github.com/cpageler93/api-client
async-http-client http http-client swift vapor
Last synced: 4 months ago
JSON representation
Easy HTTP Client for Swift
- Host: GitHub
- URL: https://github.com/cpageler93/api-client
- Owner: cpageler93
- Created: 2020-04-15T07:10:24.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-03T03:04:28.000Z (almost 4 years ago)
- Last Synced: 2025-10-03T23:39:22.682Z (4 months ago)
- Topics: async-http-client, http, http-client, swift, vapor
- Language: Swift
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# APIClient


[](https://github.com/cpageler93/api-client/blob/master/LICENSE)
[](https://twitter.com/cpageler93)
`APIClient` is an easy to use HTTP Client for Swift based on [swift-server/async-http-client](https://github.com/swift-server/async-http-client)..
## Usage Example (GitHub)
### Call your APIs like this
```swift
let githubClient = TestGitHubClient()
let repos = try githubClient.user.repositories(owner: "cpageler93").wait()
```
### GitHub API Client (simplified)
```swift
import Foundation
import NIO
import NIOHTTP1
import APIClient
// Define your clients routes
class TestGitHubClient: APIClient {
public var user: UserRoutes!
init() {
super.init(baseURL: URL(string: "https://api.github.com")!)
user = UserRoutes(apiHandler: self.handler)
}
}
// Define single routes
struct UserRoutes {
let apiHandler: APIRouteHandler
func repositories(owner: String) -> EventLoopFuture<[Repository]> {
return apiHandler.get("/users/\(owner)/repos", headers: apiHandler.githubHeader())
}
}
// Codable DTOs
struct Repository: Codable {
var id: Int
var name: String?
var fullName: String?
}
// Header Helper
private extension APIRouteHandler {
func githubHeader() -> HTTPHeaders {
return headers(["User-Agent": "Swift GitHub Client"])
}
}
```
## Need Help?
Please [submit an issue](https://github.com/cpageler93/api-client/issues) on GitHub or contact me via Mail or Twitter.
## License
This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file.