Swiftpack.co - Package - Ryucoin/NetworkUtils


Swift package for handling HTTP requests

Build Status codecov Version License Platform


NetworkUtils is a package for implementing HTTP network requests in Swift for iOS. The goal of the project is to replicate the functionality of the axios npm package used in nodejs.

It is built off of the Foundation URL Loading System (similar to Alamofire). NetworkUtils uses Google's Promises library for promise support.


NetworkUtils is available through CocoaPods. To install it, simply add the following lines to your Podfile:

pod 'NetworkUtils'

And run pod install.

Example Usage

HTTP Requests

Making an HTTP request with NetworkUtils is really simple. Use the NetworkUtils.main singleton object and one of the HTTP methods: post, get, put and delete.

Here is an example HTTP GET request:

let networkUtils = NetworkUtils.main

networkUtils.get("http://ip-api.com/json").then {(data) in
  print("Data found: \(data)")
}.catch {(error) in
  print("Error: \(error.localizedDescription)")

Error Handling

NetworkUtils offers a very basic subclass of Error named NetworkError:

public struct NetworkError: Error {
  public let msg: String
  public let code: Int

You can cast the returned Error to a NetworkError and access both of it's fields:

}.catch {(err) in
  let error = err as! NetworkError
  let code = error.code
  let msg = error.msg


NetworkUtils also offers reachability services. Access reachability with NetworkUtils.reachability such as in the following example:

let reachability = NetworkUtils.reachability

switch reachability.connection {
case .wifi:
    print("Reachable via WiFi")
case .cellular:
    print("Reachable via Cellular")
case .none:
    print("Not Reachable")


WyattMufson - cofounder of Ryu Blockchain Technologies


NetworkUtils is available under the MIT license.


Stars: 5
Help us keep the lights on


Used By

Total: 0