Easy HTTP Client without HTTP hassle
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Quack.xcodeproj
Sources
Tests
.dockerignore
.gitignore
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE
Package.pins
Package.resolved
Package.swift
README.md
run_docker_tests.sh

README.md

Quack

Codacy Badge Platforms License Twitter: @cpageler93

Quack is an easy to use HTTP Client.

With Quack HTTP calls look that beautiful and easy:

let github = GithubClient()

github.repositories(owner: "cpageler93") { repos in
    switch repos {
    case .success(let repos):
        // do something with repos (which is kind of [GithubRepository])
    case .failure(let error):
        // handle error
    }
}

Usage

Base Classes

  • QuackClient methods to make via HTTP
  • QuackModel parsing JSON to models

Code to define a Service

class GithubClient: Quack.Client {

    init() {
       super.init(url: URL(string: "https://api.github.com")!)
    }

    // synchronous
    public func repositories(owner: String) -> Quack.Result<[GithubRepository]> {
        return respondWithArray(path: "/users/\(owner)/repos",
                                model: GithubRepository.self)
    }

    // asynchronous
    public func repositories(owner: String, completion: @escaping (Quack.Result<[GithubRepository]>) -> (Void)) {
        return respondWithArrayAsync(path: "/users/\(owner)/repos",
                                     model: GithubRepository.self,
                                     completion: completion)
    }

}

class GithubRepository: Quack.Model {

    let name: String?
    let fullName: String?
    let owner: String?

    required init?(json: JSON) {
        self.name = json["name"].string
        self.fullName = json["full_name"].string
        self.owner = json["owner"]["login"].string
    }

}

Code to call a service

let github = GithubClient()

// synchronous
let repos = github.repositories(owner: "cpageler93")
switch repos {
case .success(let repos):
    // do something with repos (which is kind of [GithubRepository])
case .failure(let error):
    // handle error
}


// asynchronous
github.repositories(owner: "cpageler93") { repos in
    switch repos {
    case .success(let repos):
        // do something with repos (which is kind of [GithubRepository])
    case .failure(let error):
        // handle error
    }
}

Tests

Some tests are based on a local consul service. So start consul at first.

consul agent --dev --datacenter fra1

Need Help?

Please submit an issue on GitHub or contact me via Mail or Twitter.

License

This project is licensed under the terms of the MIT license. See the LICENSE file.