Justhttp輕量級(jí) HTTP 客戶(hù)端庫(kù)
Just 是一款用 Swift 語(yǔ)言編寫(xiě)的,受 python-requests 影響的輕量級(jí) HTTP 客戶(hù)端庫(kù)。
Just 可以讓你毫不費(fèi)力地完成如下工作:
URL 查詢(xún)
定制報(bào)文(headers)
構(gòu)建 JSON HTTP body
重定向控制
多文件上傳
Basic/Digest 認(rèn)證
Cookies
同步/異步請(qǐng)求
用戶(hù)友好的調(diào)用結(jié)果
用法:
使用 Just 發(fā)起一個(gè)請(qǐng)求的例子:
// talk to registration end point
let r = Just.post(
"http://justiceleauge.org/member/register",
data: ["username": "barryallen", "password":"ReverseF1ashSucks"],
files: ["profile_photo": .URL(fileURLWithPath:"flash.jpeg", nil)]
)
if (r.ok) { /* success! */ }
下面是使用異步方法完成上面工作的例子:
// talk to registration end point
Just.post(
"http://justiceleauge.org/member/register",
data: ["username": "barryallen", "password":"ReverseF1ashSucks"],
files: ["profile_photo": .URL(fileURLWithPath:"flash.jpeg", nil)]
) { (r)
if (r.ok) { /* success! */ }
}
你可以在這個(gè) Playground 中了解更多 Just 庫(kù)的使用方法。
安裝:
源代碼文件:只須將唯一的一個(gè)源文件拖入 playground 或者直接拖入到你的代碼中
Git 子模塊:將改 repo 作為 Git 子模塊添加到你的 git 項(xiàng)目中,然后拖動(dòng) Just.xcodeproj 到你的 Xcode 項(xiàng)目中以便你可以創(chuàng)建一個(gè)對(duì) Just.framework 的依賴(lài)并且進(jìn)行鏈接
動(dòng)態(tài)框架:因?yàn)?Just 是一個(gè)針對(duì) OS X 和 iOS 的動(dòng)態(tài)框架,所以 Carthage 就可以安裝它。
作者郵箱:[email protected]
評(píng)論
圖片
表情
