Jakub Gwóźdź
09/12/2023, 2:08 PMval dummies : List<Dummy> = client.get().body()
but I also need the body as text (before any deserialization) for auditing purposes.
The best solution I found is using the ResponseObserver and inside reading response.content.readRemaining().readText(…)
but it uses InternalApi that I need to OptIn, hardly a civilised solution
Also I’d prefer to do the same in Plugin instead of ResponseObserver…Aleksei Tirman [JB]
09/13/2023, 5:29 AM3.0.0-eap-800
). Here is an example:
val plug = createClientPlugin("myplug") {
onResponse { response ->
println("Response body: ${response.bodyAsText()}")
}
}
suspend fun main() {
val client = HttpClient(OkHttp) {
install(plug)
install(ContentNegotiation) {
json(Json {
ignoreUnknownKeys = true
})
}
}
val response = <http://client.post|client.post>("<https://httpbin.org/post>").body<HttpBin>()
println(response.origin)
}
@Serializable
data class HttpBin(val origin: String)
Jakub Gwóźdź
09/13/2023, 7:08 AM