struct User: Decodable {
var name: String
var phoneNumber: String
enum CodingKeys: String, CodingKey {
case name
case phoneNumber = "phone_number"
}
}
struct UserService: DecodableEndpoint {
typealias ResponseType = User
var baseURL: String { return "https://example.com" }
var path: String { return "/users" }
var method: HTTPMethod { return .get }
var body: Parameters { return Parameters() }
var headers: HTTPHeaders { return HTTPHeaders() }
}
// You can now use:
Bucko.shared.request(UserService()).then { user in
// Do something with user
}.catch { error in
// Do something with error
}
// or
UserService().request().then { user in
// Do something with user
}.catch { error in
// Do something with error
}
Enums still work as well:
enum UserService: Endpoint {
case index
var baseURL: String { return "https://example.com" }
var path: String { return "/users" }
var method: HTTPMethod { return .get }
var body: Parameters { return Parameters() }
var headers: HTTPHeaders { return HTTPHeaders() }
}
// Use your Endpoint
UserService.index.request(responseType: [User].self).then { users in
// Do something with users
}.catch { error in
// Do something with error
}
This PR adds Promises to Bucko.
Enums still work as well: