I'm using kittinunf/fuel to build up an app under Android.
Referring to the first example on documentation that I paste here:
import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.result.Result;
fun main(args: Array<String>) {
val httpAsync = "https://httpbin.org/get"
.httpGet()
.responseString { request, response, result ->
when (result) {
is Result.Failure -> {
val ex = result.getException()
println(ex)
}
is Result.Success -> {
val data = result.get()
println(data)
}
}
}
httpAsync.join()
}
It's possible to revert the http message body with val data = result.get()
also in case of an http status < 200 or > 299? Servers will often return extended error status message in the body and this is fully supported in iOS http stack.
In case of an error - following the example above - when result is Result.Failure
response.body()
contains the answer payload (identical asresult.get()
in case of Result.Success).