Shrimp is an simplify HTTP networking library written in Swift.
- Chainable Request / Response Methods
- Parameter Encoding
- GET / POST / PUT / DELETE
- Builtin JSON Request Serialization
- Resume Download Datas
- Download with Progress Notification
- Auto Adjust Server Date
To run the example project, clone the repo, and run pod install
from the Example directory first.
Shrimp.request(.GET, urlString: "https://httpbin.org/get")
.responseString ({ (string, response) in
debugPrint("GET: \(string)")
})
Shrimp.request(.POST, urlString: "http://www.mocky.io/v2/56c5b7a80f0000d027a204e2", parameters: ["username":"rafael",
"password":"123456"])
.responseJSONObject({ (json, response) in
debugPrint(json["first_name"])
debugPrint(json["last_name"])
debugPrint(json["gender"])
}, errorHandler: { (error) in
})
Shrimp can auto adjust server time. Get server time like this:
extension Date{
static func serverNow()->Date{
Date(ShrimpConfigure.serverTimeInterval())
}
}
Date.serverNow()
More powerfull tools use Reed Download.
DownloadManager.download(withURL: downloadURLString, withDestPath: destPath)
DownloadManager.resumeDownload(withURL: downloadURLString, withDestPath: destPath)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Start), object: nil)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Progress), object: nil)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Complete), object: nil)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Failed), object: nil)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Cancel), object: nil)
func downloadProgress(noti:Notification) {
let url = noti.userInfo!["url"] as! String
let progress = noti.userInfo!["progress"] as! Float
let bytesWritten = noti.userInfo!["bytesWritten"] as! Int64
let totalBytesWritten = noti.userInfo!["totalBytesWritten"] as! Int64
let totalBytesExpectedToWrite = noti.userInfo!["totalBytesExpectedToWrite"] as! Int64
debugPrint("url:\(url),progress:\(progress),bytesWritten:\(bytesWritten),totalBytesWritten\(totalBytesWritten),totalBytesExpectedToWrite:\(totalBytesExpectedToWrite)")
//url:http://www.abc.com/xyz.zip, progress :0.6, bytesWritten :30, totalBytesWritten :6000, totalBytesExpectedToWrite :10000
}
func downloadComplete(noti:Notification) {
let url = noti.userInfo!["url"] as! String
let destPath = noti.userInfo!["destPath"] as! String
}
DownloadManager.pauseDownload(withURL url:String)
DownloadManager.pauseDownloadAll()
DownloadManager.isDownloading(url:String)
DownloadManager.isHasResumDate(url:String)
- iOS 8.0+
- Xcode 11.3
- Swift 5
Shrimp is available through CocoaPods. To install it, simply add the following line to your Podfile:
# swift5+ ,ios 8.0+
pod "Shrimp"
If you're using Carthage, you can add a dependency on Shrimp by adding it to your Cartfile:
github "KevinZhouRafael/Shrimp"
Rafael Zhou
- Email me: [email protected]
Shrimp is available under the MIT license. See the LICENSE file for more info.