Swiftpack.co - Package - graemer957/SimpleRESTLayer

SimpleRESTLayer pipeline status

codebeat badge Language Platforms Swift PM Carthage compatible Twitter 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.


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


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)")



  • 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


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.


Copy the Swift files from SimpleRESTLayer into your project.


  • [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...


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


Stars: 0
Help us keep the lights on


Used By

Total: 0


v0.7.2 - Feb 24, 2018

Built using Xcode v9.2 with Swift v4.0.3


  • Fixed incorrect encoding of parameters in body

v0.7.1 - Feb 22, 2018

Built using Xcode v9.2 with Swift v4.0.3


  • Change access modifiers on Response

v0.7.0 - Feb 9, 2018

Built using Xcode v9.2 with Swift v4.0.3


  • 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


  • Fixed incorrect spelling of unauthorised

v0.6.0 - Dec 13, 2017

Built using Xcode v9.2 with Swift v4.0.3


  • 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


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

v0.5.0 - Dec 13, 2017

Built using Xcode v9.2 with Swift v4.0.3


  • Rename Response as Result, which is more in-keeping with other projects in the Swift community
  • Result can now failure can now be any Error
  • Successful results now include a Response allowing access to a type safe HTTP status code and headers
  • Calling RESTClient.execute permits passing your own JSONDecoder, by default a new one will be created
  • You can now set RESTClient.queue to be DispatchQueue on which completion handlers should be called
  • To access the raw data of a response pass in a result type of Data
  • Add unwrap method to Result type, inspiration from Cocoa with Love
  • Tweak signature of Request.with to improve readability at call site