Net alternatives and similar libraries
Based on the "Network" category.
Alternatively, view Net alternatives based on common mentions on social networks and blogs.
-
Perfect
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and moreβ¦) -
Reachability.swift
Replacement for Apple's Reachability re-written in Swift with closures -
SwiftSoup
SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS) -
Netfox
A lightweight, one line setup, iOS / OSX network debugging library! π¦ -
SwiftHTTP
Thin wrapper around NSURLSession in swift. Simplifies HTTP requests. -
APIKit
Type-safe networking abstraction layer that associates request type with response type. -
Swifton
A Ruby on Rails inspired Web Framework for Swift that runs on Linux and OS X -
Zewo
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines. -
ResponseDetective
Sherlock Holmes of the networking layer. :male_detective: -
SwiftWebSocket
A high performance WebSocket client library for swift. -
BlueSocket
Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. -
Connectivity
π Makes Internet connectivity detection more robust by detecting Wi-Fi networks without Internet access. -
WKZombie
WKZombie is a Swift framework for iOS/OSX to navigate within websites and collect data without the need of User Interface or API, also known as Headless browser. It can be used to run automated tests / snapshots and manipulate websites using Javascript. -
Pitaya
π A Swift HTTP / HTTPS networking library just incidentally execute on machines -
Express
Swift Express is a simple, yet unopinionated web application server written in Swift -
PeerKit
An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps -
Heimdallr.swift
Easy to use OAuth 2 library for iOS, written in Swift. -
Socks
π Non-blocking TCP socket layer, with event-driven server and client. -
Embassy
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux -
Digger
Digger is a lightweight download framework that requires only one line of code to complete the file download task -
SOAPEngine
This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and AppleTV app. -
SwiftyOAuth
A simple OAuth library for iOS with a built-in set of providers -
BigBrother
Automatically sets the network activity indicator for any performed request.
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Net or a related project?
Popular Comparisons
README
Net
Net is a HttpRequest wrapper written in Swift
Features
- [x] GET, POST, PUT, DELETE method
- [x] Powerful request params: nested params, number, string, dic, array, image, data
- [x] Json, Image, Xml Response
- [x] Download file: resume, suspend, cancel
- [x] Upload file, data, params(multi-part)
- [x] Progress closure
- [x] Background donwload, upload
- [x] Authentication
- [x] Batch of operations
- [x] BaseURL
- [x] Customizable header
Demo app
Usage
Use one of the following methods to create a Net instance
// without baseURL
let net = Net()
// with baseURL
let net = Net(baseUrlString: "http://www.puqiz.com/")
HttpRequest
GET
Request
let url = "get_path"
let params = ["integerNumber": 1, "doubleNumber": 2.0, "string": "hello"]
net.GET(url, params: params, successHandler: { responseData in
let result = responseData.json(error: nil)
NSLog("result \(result)")
}, failureHandler: { error in
NSLog("Error")
})
// you can also make a request with absolute url
let url = "http://www.puqiz.com/get_path"
net.GET(absoluteUrl: url, params: params, successHandler: { responseData in
let result = responseData.json(error: nil)
NSLog("result \(result)")
}, failureHandler: { error in
NSLog("Error")
})
You can also use nested params
// nested params
let params = ["string": "test",
"integerNumber": 1,
"floatNumber": 1.5,
"array": [10, 20, 30],
"dictionary": ["x": 100.0, "y": 200.0],
"image": NetData(pngImage: img, filename: "myIcon")]
By using responseData in sucessHandler closure you can quickly
- get json dictionary
- get image
- parse xml
for GET, POST, PUT, DELETE request.
// get json dictionary from response data
let jsonDic = responseData.json(error: error)
// get image from response data
let image = responseData.image()
// parse xml with delegate
let result = responseData.parseXml(delegate: self)
POST
Request
Net will automatically check your params to send request as a URL-Encoded request or a Multi-Part request. So you can easily post with number, string, image or binary data.
- URL-Encoded Request
let url = "post_path"
let params = ["string": "test", "integerNumber": 1, "floatNumber": 1.5]
net.POST(url, params: params, successHandler: { responseData in
let result = responseData.json(error: nil)
NSLog("result: \(result)")
}, failureHandler: { error in
NSLog("Error")
})
- Multi-Part Request
let url = "post_path"
let img = UIImage(named: "puqiz_icon")
let params = ["string": "test", "integerNumber": 1,
"icon": NetData(pngImage: img, filename: "myIcon")]
net.POST(url, params: params, successHandler: { responseData in
let result = responseData.json(error: nil)
NSLog("result: \(result)")
}, failureHandler: { error in
NSLog("Error")
})
PUT
Request
let url = "put_path"
let params = ["string": "test", "integerNumber": 1, "floatNumber": 1.5]
net.PUT(url, params: params, successHandler: { responseData in
let result = responseData.json(error: nil)
NSLog("result: \(result)")
}, failureHandler: { error in
NSLog("Error")
})
DELETE
Request
let url = "delete_path"
let params = ["id": 10]
net.DELETE(url, params: params, successHandler: { responseData in
NSLog("result: \(result)")
}, failureHandler: { error in
NSLog("Error")
})
Task
Before using download/upload function you have to call setupSession
method to setup the session.
// setup session without backgroundIdentifier
net.setupSession()
To perform background downloads or uploads, you have to call setupSession
method with a background identifier string. Then your download/upload tasks can be run even when the app is suspended, exits or crashes.
// setup session with backgroundIdentifier
net.setupSession(backgroundIdentifier: "com.nghialv.download")
// you can set eventsForBackgroundHandler closure
// this closure will be invoked when a task is completed in the background
net.eventsForBackgroundHandler = { urlSession in
urlSession.getDownloadingTasksCount{ downloadingTaskCount in
if downloadingTaskCount == 0 {
NSLog("All files have been downloaded!")
}
}
}
Download
let downloadTask = net.download(absoluteUrl: url, progress: { progress in
NSLog("progress \(progress)")
}, completionHandler: { fileUrl, error in
if error != nil {
NSLog("Download failed")
}
else {
NSLog("Downloaded to : \(fileUrl)")
}
})
// you can control your task
downloadTask.resume()
downloadTask.suspend()
downloadTask.cancel()
Upload
- Upload with file path
let task = net.upload(absoluteUrl: url, fromFile: file, progressHandler: { progress in
NSLog("progress \(progress)")
}, completionHandler: { error in
if error != nil {
NSLog("Upload failed : \(error)")
}
else {
NSLog("Upload completed")
}
})
- Upload with data
let yourData = NSData(...)
net.upload(absoluteUrl: url, data: yourData, progressHandler: { progress in
NSLog("progress: \(progress)")
}, completionHandler: { error in
NSLog("Upload completed")
})
- Upload with params
let image = UIImage(named: "image_file")
let imageData = UIImagePNGRepresentation(image)
let params = ["number": 1, "string": "net", "data": imageData]
net.upload(absoluteUrl: imgUrl, params: params, progressHandler: { progress in
NSLog("progress: \(progress)")
}, completionHandler: { error in
NSLog("Upload completed")
})
By default, the upload task will be performed as POST method and
Content-Type
=application/octet-stream
(upload with file or data)Content-Type
=multipart/form-data
(upload with params)
But you can configure the upload task before resuming.
// set method
yourUploadTask.setHttpMethod(.PUT)
// set header field
yourUploadTask.setValue(value: "your_value", forHttpHeaderField: "header_field")
Integration
Just drag Net folder to the project tree