Reactor
Last updated
Was this helpful?
Was this helpful?
data class Guest(val name: String)
object GuestMapper : ResponseDeserializable<Guest> {
override fun deserialize(content: String) =
jacksonObjectMapper().readValue<Guest>(content)
}
Fuel.get("/guestName").monoResultObject(GuestMapper)
.map(Result<Guest, FuelError>::get)
.map { (name) -> "Welcome to the party, $name!" }
.onErrorReturn("I'm sorry, your name is not on the list.")
.subscribe(::println)FuelManager.instance.basePath = "https://httpbin.org"
Fuel.get("/status/404").monoResponse()
.filter(Response::isSuccessful)
.switchIfEmpty(Fuel.get("/status/200").monoResponse())
.map(Response::statusCode)
.subscribe(::println)