歡迎加入QQ討論群258996829

Swift HTTP 網(wǎng)絡(luò)庫 Networking

發(fā)布時間:2017-07-07 15:27  回復(fù):0  查看:5879  感興趣:106  贊:1   最后回復(fù):2017-07-07 15:27  
使用簡單、功能驚喜,基于 NSURLSession 的網(wǎng)絡(luò)封裝庫。功能包括帶身份驗證請求,支持單元測試(mocking/stubbing),異步執(zhí)行,圖片下載及緩存等實用特性。
GET示例
let networking = Networking(baseURL: "http://httpbin.org")
networking.get("/get") { result in
    switch result {
    case .success(let response):
        let json = response.dictionaryBody
        // Do something with JSON, you can also get arrayBody
    case .failure(let response):
        // Handle error
    }
}
POST示例
let networking = Networking(baseURL: "http://httpbin.org")
networking.post("/post", parameters: ["username" : "jameson", "password" : "secret"]) { result in
    /*
    {
        "json" : {
            "username" : "jameson",
            "password" : "secret"
        },
        "url" : "http://httpbin.org/post",
        "data" : "{"password" : "secret","username" : "jameson"}",
        "headers" : {
            "Accept" : "application/json",
            "Content-Type" : "application/json",
            "Host" : "httpbin.org",
            "Content-Length" : "44",
            "Accept-Language" : "en-us"
        }
    }
    */
}

相關(guān)開源代碼

您還未登錄,請先登錄

熱門帖子

最新帖子

?