Introducing NetworkUtils for Swift

A simple open source class for promise based HTTP requests

In the process of building the Ryu Ecosystem we are creating numerous Swift projects that require the use of HTTP requests. We decided to standardize the way our applications work and interact with our backend systems.

We’re excited to announce the release of NetworkUtils - available through Cocoa Pods. NetworkUtils is designed to replicate the functionality of the axios npm package used in nodejs development. It is built off of the Foundation URL Loading System and uses Google’s Promises library.

NetworkUtils vs Pre-Existing Libraries

NetworkUtils behaves very similarly to other pre-existing libraries, with the added benefit of its use of promise syntax. For example, here’s how you would call an HTTP GET request to Google with NetworkUtils vs Alamofire and SwiftHTTP.

NetworkUtils

import NetworkUtils
networkUtils.get("http://google.com").then {(data) in
print(data)
}.catch {(error) in
print(error.localizedDescription)
}

Alamofire

import Alamofire
Alamofire.request("http://google.com").response { response in
if let error = response.error {
print(error.localizedDescription
} else {
if let data = response.data {
print(data)
}
}
}

SwiftHTTP

import SwiftHTTP
HTTP.GET("http://google.com") { response in  
if let error = response.error {
print(error.localizedDescription)
} else {
if let data = response.data {
print(data)
}
}
}

Trade-Offs and Looking Forward

If you are looking for implementing more than just HTTP requests in your Swift project, NetworkUtils may not be the right choice for you, as there are numerous features not yet implemented in NetworkUtils that exist in both Alamofire and SwiftHTTP.

NetworkUtils was designed to replicate axios and is primarily focused on making HTTP requests as clean as possible. We plan to add additional network connection features in the future— we added Reachability services with a modification of ReachabilitySwift — and are working toward fully matching the capabilities of Alamofire and SwiftHTTP.

We’re excited to share NetworkUtils and look forward to feedback. If you want to learn more, check out the GitHub repo and/or send me an email at wyatt@ryucoin.com.