Swiftpack.co - graemer957/SimpleRESTLayer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by graemer957.
graemer957/SimpleRESTLayer v0.7.3
A simple REST layer, written in Swift built on top of URLSession
⭐️ 0
🕓 1 year ago
.package(url: "https://github.com/graemer957/SimpleRESTLayer.git", from: "v0.7.3")

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

  • ☑ Supports Codable models
  • ☑ JSON / URL Encoding
  • ☑ Custom HTTP Headers
  • ☑ 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

  • ☑ Add support for fastlane
  • ☐ Add unit tests
  • ☐ Add code coverage with codecov.io
  • ☑ Add SwiftLint
  • ☑ Add support for Carthage
  • ☐ Add support for CocoaPods
  • ☑ Add codebeat.co
  • ☑ 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
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

5 years ago

Built using Xcode v10.0 with Swift v4.2

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics