Swiftpack.co - rorodriguez116/Rapide as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by rorodriguez116.
rorodriguez116/Rapide 0.3.5
A lightweight wrapper library for networking and parsing tasks
⭐️ 0
🕓 2 weeks ago
iOS macOS
.package(url: "https://github.com/rorodriguez116/Rapide.git", from: "0.3.5")

Rapide

Rapide is a fast and lightweight combine-based wrapper on URLSession. Rapide provides a simple and easy to use API for performing REST request and effortless mapping from and to JSON models, using Swift's native Codable and Decodable protocols.

Usage

As an example, we'll perform a get request to the following API: https://openexchangerates.org/api/convert/2000/GBP/EUR?app_id=XYZ


Rapide
    .https
    .host("openexhangerates.org")
    .path("/api/convert/2000/GBP/EUR")
    .authorization(.none)
    .params(["app_id":"XYZ"])
    .execute(.get, decoding: String.self, customErrorType: MyErrorType.self)
    .sink { completion in
        if case let .failure(error) = completion {
            if let err = error as? MyErrorType {
                // Handle your custom error
                print(err.myCustomProperty)
            } else {
                // Handle error 
                print(error)
            }
        }
    } receiveValue: { val in
        // success
    }
    .store(in: &self.subscriptions)

The presented code is very easy to read. First we specify the connection scheme we want to use, Rapide offers http, https and ftp. Then we provide the host and path to our API, the parameters we want to pass the API to and we finalize calling execute, which will return a combine publisher that will execute the specified http method and map the response to the provided Codable conforming type.

GitHub

link
Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

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