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.
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)")
}
}
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.
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.
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:
Result
typeSimpleRESTLayer is released under the Apache 2.0 license. See LICENSE for details.
link |
Stars: 0 |
Last commit: 1 year ago |
Built using Xcode v10.0 with Swift v4.2
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics