GitHub API client written in Swift with the help of Apple NIO

What's New



github client is now public


Slack iOS macOS Ubuntu Swift 5.1 Vapor 4

Super simple to use Github API client library written using Apple NIO


The below probably don't contain all methods from the spec but it's a good start ...

  • Organizations
  • Repos
  • Files
  • File contents
  • Comments
  • Commits (full management)
  • Branches
  • Webhooks
  • Tags
  • Releases
  • PR's
  • Issues


Add to your Package.swift file

.package(url: "", from: "1.0.0")

Don't forget about your target

    name: "App",
    x: [


let config = Github.Config(
    username: "orafaj",
    token: token,
    server: ""
let github = try Github(config)

// or

let github = try Github(config, eventLoop: eventLoop)

// or 

let github = try Github(config, eventLoopGroupProvider: .createNew)

Use in iOS and server side frameworks

Although this library has been only tested with Vapor 4, using Apple NIO HHTPClient should be compatible with any iOS or server side project.

Please let us know on our slack here how you getting on or should you need any support!

Use in Vapor 4?

import GitHubKit

// In configure.swift
services.register(Github.self) { container in
    let config = Github.Config(
        username: "orafaj",
        token: token,
        server: ""
    return try Github(config, eventLoop: container.eventLoop)

// In routes (or a controller)
r.get("github", "organizations") { req -> EventLoopFuture<[Organization]> in
    let github = try c.make(Github.self)
    return try Organization.query(on: github).getAll().map() { orgs in
        return orgs


Adding a new API call is ... surprisingly super simple too

Lets say you need to add a detail of a user

Go to the documentation

Autogenerate a model

Copy the example JSON, for example:

  "login": "octocat",
  "id": 1,
  "node_id": "MDQ6VXNlcjE=",
  "avatar_url": "",
  "gravatar_id": "",
  "url": "",
  "html_url": "",
  "followers_url": "",
  "following_url": "{/other_user}",
  "gists_url": "{/gist_id}",
  "starred_url": "{/owner}{/repo}",
  "subscriptions_url": "",
  "organizations_url": "",
  "repos_url": "",
  "events_url": "{/privacy}",
  "received_events_url": "",
  "type": "User",
  "site_admin": false,
  "name": "monalisa octocat",
  "company": "GitHub",
  "blog": "",
  "location": "San Francisco",
  "email": "",
  "hireable": false,
  "bio": "There once was...",
  "public_repos": 2,
  "public_gists": 1,
  "followers": 20,
  "following": 0,
  "created_at": "2008-01-14T04:33:35Z",
  "updated_at": "2008-01-14T04:33:35Z"

Go to the and convert the JSON into a model ... you might want to mess a bit with the settings to keep the models consistent with ones in the project already. Also, any sub structs (unless they can be used elsewhere) should be moved inside of the parent model.

Oh yeah ... and call the main class User! :) ...

Import Vapor and conform the main model to Content instead of Codable.

Make a request extension

First you need to conform the User model to Queryable. This will enable the User.query(on: container) method.

extension User: Queryable { }

Next we create an extension on QueryableProperty which is generated each time you request a query on a container from the previous step. Make sure you specify the QueryableType == User

extension QueryableProperty where QueryableType == User {
    /// Get all organizations for authenticated user
    public func get() throws -> EventLoopFuture<User> {
        return try github.get(path: "user")

All done

You should be able to call try User.query(on: c).get() and get an EventLoopFuture<User> with the details of your authenticated user.


Ondrej Rafaj @rafiki270

(It wasn't my token after all, was it?!)


MIT; See LICENSE file for details.


  • Swift Tools 5.1.0
View More Packages from this Author


Last updated: Wed May 17 2023 09:05:25 GMT-0500 (GMT-05:00)