Swiftpack.co -  graemer957/SimpleRESTLayer as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
graemer957/SimpleRESTLayer
A simple REST layer, written in Swift built on top of URLSession
.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: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

2 years ago

Built using Xcode v10.0 with Swift v4.2

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