Hello, I am using a Ktor client with the Json feat...
# ktor
m
Hello, I am using a Ktor client with the Json feature to receive some Json objects, but I also need to access the response headers. I can see them if I get the HttpResponse object, but then I don't have my deserialized Json object. How do I retrieve both the Json object and the response headers?
j
What is the usecase? Do you need to handle the headers at the same place as where you handle the response body? Because otherwise you could use an interceptor/feature to first handle headers.
j
just tried here and you should be able to do something like
Copy code
suspend fun fetchPeople(): AstroResult {
    val response = client.get<HttpResponse>("$baseUrl/astros.json")
    val headers = response.headers
    val data = response.receive<AstroResult>()
    return data
}
m
@John O'Reilly Thank you, that's what I've been looking for.
👍 1