Swiftpack.co - Package - TherapyChat/Edge

build swift platforms cocoapods carthage coverage license

Table of Contents

Overview

Edge is a lightweight network abstraction layer. We designed Edge to be simple to use and also very flexible. We oriented this framework to make API REST requests. We have added some useful features like Authentication, Network activity indicator, and custom logging with Interceptors. This network layer queues all requests to avoid making redundant network requests. Also, when the user loses the connection, the requests are queued and are paused until the user recovers the network connection.

Features

  • Generic, protocol-based task implementation
  • Eliminates redundant network requests
  • Enqueue requests when user lost connection
  • Singleton free
  • Super friendly API
  • Stop and go engine
  • No external dependencies
  • Robust Interceptor system
  • Minimal implementation
  • Support for iOS/macOS/tvOS/watchOS/Linux
  • Support for CocoaPods/Carthage/Swift Package Manager

Getting Started

This is a tiny example to build and execute a network request with Edge.

enum Foo {
    case bar
}

extension Foo: Task {
    var path: String {
        return "get"
    }
}

let client = Edge(with "https://httpbin.org")

client.request(Foo.bar) { (result: JSONResponse) in
    switch result {
    case .success(let JSON):
        print(JSON)
    case .failure(let error):
        print(error)
    }
}

Interceptors

Authentication

You can authenticate all requests with Authorization.


let jwt = Authorization(scheme: .Bearer, token: "1")

client.add(interceptor: jwt)

Network Activity Indicator

You can show on status bar the network activity indicator with Activity.


let networkActivity = Activity()

client.add(interceptor: networkActivity)

Custom Logger

You can simple build a network interceptor to log all requests.


struct Logger: Interceptor {

    func willExecute(request: Request) {
        print(request)
    }

    func process(response: Response) {
        print(response)
    }

}

client.add(interceptor: Logger())

You can check the Edge.playground to experiment with more examples. If you need to see deeply information you can check our Documentation

Installation

CocoaPods

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

platform :ios, '10.0'
use_frameworks!
swift_version = '3.0'

target 'MyApp' do
  pod 'Edge'
end

Carthage

You can also install it via Carthage. To do so, add the following to your Cartfile:

github 'therapychat/Edge'

Swift Package Manager

You can use Swift Package Manager and specify dependency in Package.swift by adding this:

.Package(url: "https://github.com/therapychat/Edge.git", majorVersion: 0)

Author

Sergio Fernández, fdz.sergio@gmail.com

Contribution

For the latest version, please check develop branch. Changes from this branch will be merged into the master branch at some point.

License

Edge is available under the Apache License 2.0. See the LICENSE file for more info.

Changelog

See CHANGELOG file.

Github

link
Stars: 6
Help us keep the lights on

Dependencies

Used By

Total: 0