Swiftpack.co - Package - alchemy-swift/papyrus-alamofire

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

alchemy-swift/papyrus-alamofire

Requesting Papyrus Endpoints with Alamofire

PapyrusAlamofire

Requesting Papyrus API definitions with Alamofire.

Usage

Define an API...

class TodosAPI: EndpointGroup {
    @GET("/todos")
    var getAll: Endpoint<GetTodosRequest, [TodoDTO]>

    struct GetTodosRequest: EndpointRequest {
        @URLQuery
        var limit: Int

        @URLQuery
        var incompleteOnly: Bool
    }

    struct TodoDTO: Codable {
        var name: String
        var isComplete: Bool
    }
}

...and request it.

import PapyrusAlamofire

let todosAPI = TodosAPI(baseURL: "http://localhost:8888")
todosAPI.getAll
    .request(.init(limit: 50, incompleteOnly: true)) { response, todoResult in
        switch todoResult {
        case .success(let todos):
            for todo in todos {
                print("Got todo: \(todo.name)")
            }
        case .failure(let error):
            print("Got error: \(error).")
        }
    }

Github

link
Stars: 0
Last commit: 1 week ago

Releases

v0.1.0 Initial Release - 2021-01-16T20:31:52