Swiftpack.co - vivalalova/FetchSwift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by vivalalova.
vivalalova/FetchSwift 1.0.3
Combine
⭐️ 0
🕓 2 years ago
iOS macOS
.package(url: "https://github.com/vivalalova/FetchSwift.git", from: "1.0.3")

FetchSwift

Usage

final class JsonPlaceholderAPI: Fetch {
    /// ref: https://jsonplaceholder.typicode.com/
    var domain: String = "https://jsonplaceholder.typicode.com/"

    var decoder = JSONDecoder()

    var encoder = JSONEncoder()

    static var shared: JsonPlaceholderAPI = JsonPlaceholderAPI()

    func willSend(params: [String: Any], method: FetchSwift.Method, path: String) -> Params {
        params
    }

    func willSend(request: URLRequest, method: FetchSwift.Method, path: String, params: [String: Any]) -> URLRequest {
        request
    }

    func show(progress: Float?) {}

    func hide(progress: Float?) {}
}

extension JsonPlaceholderAPI {
    struct Todo: Codable {
        var id: Int?
        var userId: Int?
        var title: String?
        var completed: Bool?
    }

    func todos() -> Response<[Todo]> {
        self.fetch(path: "todos")
    }
}

GitHub

link
Stars: 0
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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