测试已测试 | ✓ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2016 年 7 月 |
SPM支持 SPM | ✗ |
由 Olaf A. Øvrum 维护。
依赖关系 | |
Alamofire | >= 0 |
SwiftyJSON | >= 0 |
Alamofire 的 REST 客户端包装器。它还利用了 SwiftyJSON。
目前支持的方法
GET
POST
PUT
PATCH
DELETE
import RestFire
// Initiate the RestFire client
let restFire = RestFire(baseUrl: "https://some.website.com/api")
restFire["comments"].get().response {
value, error in
if let error = error {
return print("Error fetching comments: \(error)")
}
if let value = value {
let firstComment = value[0]
print(firstComment["author"])
}
}
let newComment = ["author": "John Doe", "message": "This is really cool!"]
restFire["comments"].post(newComment).response {
value, error in
if let error = error {
return print("Error posting comment: \(error)")
}
if let value = value {
print(value)
}
}
restFire["posts"][3]["comments"].get().response {
value, error in
print(error)
print(value)
}
响应闭包中的 value
变量是 JSON 类型,这种类型来自 SwiftyJSON。
error
变量是 NSError 类型。这可能在 'userInfo' 字典中包含 'reason'。