Swiftpack.co - Package - graemer957/SimpleRESTLayer

SimpleRESTLayer pipeline status

codebeat badge Language Platforms Swift PM Carthage compatible License

A simple REST layer, written in Swift built on top of URLSession. Thanks to the new JSON Encoder/Decoder and Codable in Swift 4 is extremely lightweight and easy to use.

Features

  • [x] Supports Codable models
  • [x] JSON / URL Encoding
  • [x] Custom HTTP Headers
  • [x] Complete working example

Usage

SimpleRESTLayer should be simple to use and have a self explanatory API.

struct IP: Codable {
    let address: String
    
    enum CodingKeys: String, CodingKey {
        case address = "origin"
    }
}

import SimpleRESTLayer
let client = RESTClient()

let request = Request.with("https://httpbin.org/ip")
client.execute(request) { (result: Result<IP>) in
    do {
        let (response, ip) = try result.unwrap()
        print("Response was \(response) and your IP address is \(ip.address)")
    } catch {
        print("Error: \(error)")
    }
}

Dependancies

Requirements

  • Swift 4.0+ / Xcode 9.0+
  • iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
  • Ubuntu 14.04 / Ubuntu 16.04 / Ubuntu 16.10

Installation

Swift Package Manager

In your Packages.swift add:

.package(url: "https://gitlab.com/optimisedlabs/simplerestlayer.git", .from: "0.7.0")

NOTE: .upToNextMinor(from: "0.7.0") might be better whilst the API stablises.

Dynamic Framework

Download release zip and add to your Xcode project as an embedded framework. The framework contains slices for armv7 and arm64 (see ARCHS_STANDARD). These are always built using the latest version of Xcode / Swift and macOS.

Manually

Copy the Swift files from SimpleRESTLayer into your project.

TODO

  • [x] Add support for fastlane
  • [ ] Add unit tests
  • [ ] Add code coverage with codecov.io
  • [x] Add SwiftLint
  • [x] Add support for Carthage
  • [ ] Add support for CocoaPods
  • [x] Add codebeat.co
  • [x] Add support for Swift Package Manager

Acknowledgements and thanks

The ideas and inspiration for this framework have been sourced from a number of different sources over the years. Whilst this is by no means an exhaustive list, I would like to thank:

  • Apple, standing on the shoulders of giants...
  • Cocoa with Love blog for various great articles and ideas over the years, not least of all the Result type
  • codebeat for plenty of suggestions on where to focus to improve code quality
  • More to come...

License

SimpleRESTLayer is released under the Apache 2.0 license. See LICENSE for details.

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

v0.7.3 - Oct 8, 2018

Built using Xcode v10.0 with Swift v4.2

v0.7.2 - Feb 24, 2018

Built using Xcode v9.2 with Swift v4.0.3

Fixed

  • Fixed incorrect encoding of parameters in body

v0.7.1 - Feb 22, 2018

Built using Xcode v9.2 with Swift v4.0.3

Fixed

  • Change access modifiers on Response

v0.7.0 - Feb 9, 2018

Built using Xcode v9.2 with Swift v4.0.3

Changes

  • Add support for HTTP Basic Auth and Bearer Tokens
  • Add date/time to log output
  • Log the request when it's made and the response when it is back
  • Add map and flapMap to Result

Fixes

  • Fixed incorrect spelling of unauthorised

v0.6.0 - Dec 13, 2017

Built using Xcode v9.2 with Swift v4.0.3

Changes

  • If response is unsuccessful, ResponseError now contains the Data sent by server
  • Tweak execute API by hiding first parameter to improve readability at call site
  • Rename name of completion handler more in keeping with other platform frameworks
  • Calling extension URLRequest.addJSONBody permits passing your own JSONEncoder, by default a new one will be created
  • Rename parameter on Request.with to make its purpose clearer

Fixes

  • Fix issue on Linux where subsequent requests would not use supplied URLSessionConfiguration