https://github.com/bdrelling/goatherb
Cross-platform Swift library for accessing the public GitHub API.
https://github.com/bdrelling/goatherb
github github-api ios linux macos swift tvos vapor watchos
Last synced: 10 months ago
JSON representation
Cross-platform Swift library for accessing the public GitHub API.
- Host: GitHub
- URL: https://github.com/bdrelling/goatherb
- Owner: bdrelling
- License: mit
- Created: 2022-08-24T02:08:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-29T18:53:23.000Z (almost 3 years ago)
- Last Synced: 2025-03-25T13:21:36.493Z (11 months ago)
- Topics: github, github-api, ios, linux, macos, swift, tvos, vapor, watchos
- Language: Swift
- Homepage: https://briandrelling.com
- Size: 95.7 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GoatHerb
[](https://github.com/bdrelling/GoatHerb/actions/workflows/tests.yml)

[](https://github.com/bdrelling/GoatHerb/tags)
[](https://swiftpackageindex.com/bdrelling/GoatHerb)
[](https://swiftpackageindex.com/bdrelling/GoatHerb)
[](https://github.com/bdrelling/GoatHerb/blob/main/LICENSE)
**GoatHerb** is a cross-platform Swift library for accessing the GitHub API.
## Features
### General
- [x] Compatible with [swift-log](https://github.com/apple/swift-log).
- [x] Full concurrency (async/await) support.
- [x] Cross-platform support:
- [x] iOS
- [x] macOS
- [x] tvOS
- [x] watchOS
- [x] Linux _(optimized for Server-side Swift)_
> Most cross-platform SDKs simply replace Foundation's `URLSession` with SwiftNIO's `AsyncHTTPClient` and call it a day. Not GoatHerb! GoatHerb is built on top of [KippleNetworking](https://github.com/swift-kipple/Networking), which intelligently chooses between Foundation's `URLSession` or SwiftNIO's `AsyncHTTPClient` depending on the platform, ensuring optimal networking for the platform it's running on.
### GitHub API
- [x] Get Rate Limit
- [x] Get User
- [x] Get Organization
- [x] Get User Repositories
- [x] Get Organization Repositories
- [x] Get Repository
> That's it for now! If you're looking for a more feature-complete SDK, check out [the list of GitHub SDKs on Swift Package Index](https://swiftpackageindex.com/search?query=GitHub).
## Usage
Create a `GitHub` object.
```swift
let gitHub = GitHub()
```
You can optionally provide an `accessToken` in the initializer, or via setting the `GITHUB_ACCESS_TOKEN` or `GITHUB_TOKEN` environment variable.
```swift
let gitHub = GitHub(accessToken: "")
```
From there, requests are extremely straight-forward. Here are some examples:
```swift
// Get a user.
let user = try await self.gitHub.getUser("bdrelling")
// Get an organization.
let organization = try await self.gitHub.getOrganization("swift-kipple")
// Get all repositories for a user.
let repositories = try await self.gitHub.getRepositories(user: "bdrelling")
// Get all repositories for an organization.
let repositories = try await self.gitHub.getRepositories(org: "swift-kipple")
```
## Contributing
Discussions, issues, and pull requests are more than welcome! I'm happy to extend the functionality of this library, with respect to the features listed in the [Out of Scope](#out-of-scope) section.
If opening a pull request, please ensure that the package retains _as close to_ 100% code coverage as possible.
## Credits
Special thanks to [@boiarqin](https://github.com/boiarqin) for providing me with an unforgettable repository name.
## License
This project is released under the MIT license. See [LICENSE](/LICENSE) for details.