Latest 1.0.0
Homepage https://github.com/harshvishu/GoldenDragon
License MIT
Platforms ios 10.0
Authors

iOS Networking Framework

Image of Yaktocat

How to use?

  • Extend EndPointType protocol
  • Subclass Router in order to make the network calls
  • Use Codable protocols
enum Api {
    case search(query: String)
}

extension Api: EndPointType {

    public  var host: String {
        return "api.github.com"
    }

    public  var scheme: String {
        return "https"
    }

    public  var path: String {
        switch self {
        case .search:
            return "/search/repositories"
        }
    }

    public var httpMethod: HTTPMethod {
        switch self {
        case .search:
            return .get
        }
    }

    public var task: HTTPTask {
        switch self {
        case .search(let query):
            let params: Parameters = [
                "q": query
            ]
            return .requestParameters(bodyParameters: nil, bodyEncoding: .urlEncoding, urlParameters: params)
        }
    }

    public var headers: HTTPHeaders? {
        return nil
    }
}
 private var router: Router<Api> = Router<Api>()

 func testApi() {

        let expect: Future<SearchResult> = router.request(Api.search(query: "swift"))
        expect.observe { result in
            switch result {
            case .success(let searchData):
                print("(searchData.totalCount) repositories found")
            case .failure(let error):
                print(error.localizedDescription)
            }
        }        
    }

 struct SearchResult: Codable {
        let totalCount: Int
        let items: [Item]

        enum CodingKeys: String, CodingKey {
            case totalCount = "total_count"
            case items
        }
    }

    struct Item: Codable {
        let id: Int
        let htmlURL: String
        let description: String

        enum CodingKeys: String, CodingKey {
            case id
            case htmlURL = "html_url"
            case description
        }
    }

Latest podspec

{
    "name": "GoldenDragon",
    "version": "1.0.0",
    "summary": "A networking framework",
    "description": "GoldenDragon is a set of files to perform basic networking operations",
    "homepage": "https://github.com/harshvishu/GoldenDragon",
    "license": "MIT",
    "authors": {
        "harsh": "[email protected]"
    },
    "source": {
        "git": "https://github.com/harshvishu/GoldenDragon.git",
        "tag": "1.0.0"
    },
    "source_files": "GoldenDragon",
    "swift_version": "5.0",
    "platforms": {
        "ios": "10.0"
    },
    "documentation_url": "https://github.com/harshvishu/GoldenDragon"
}

Pin It on Pinterest

Share This