Hi. I am using Retrofit in an Android project, and...
# ktor
m
Hi. I am using Retrofit in an Android project, and want to migrate some parts to Ktor Client as a PoC. I am having trouble to find a way of getting the wrapped return value as Retrofit does. e.g.
suspend fun get() :Response<DataValue>
in Retrofit would give me a response code, a way to parse an error model returned, etc easily. How can I have this in Ktor? Haven't seen it in the examples, unless using the
HttpResponseValidator
function to the Client configuration, which I will have to configure per api call. I am pretty sure there is an easier way, but could someone point me to a good example please?
r
if I understood you correctly, you are looking for
Copy code
val response = client.get<HttpResponse>(request)
val status = response.status
val content = response.receive<DataValue>
m
ah, thank you! will give it a try!