Renaud
04/22/2022, 1:58 PMNo request transformation found
. Does it sound familiar to someone?
Looking a ktor source code, it comes from HttpRequest.kt
body as? OutgoingContent ?: error("No request transformation found: $body")
It seems related to the setBody function in my test
@Test
fun testPostRandom() = testApplication {
val response = <http://client.post|client.post>("/random") {
contentType(ContentType.Application.Json)
setBody(PostRandomRequest(listOf("Jet", "Brains")))
}
assertEquals("Hello World!", response.bodyAsText())
assertEquals(HttpStatusCode.Created, response.status)
}
Aleksei Tirman [JB]
04/22/2022, 2:15 PMContentNegotiation
plugin into the client to serialize the request body:
val client = createClient {
install(ContentNegotiation) {
json()
}
}
val response = <http://client.post|client.post>("/random") {
contentType(ContentType.Application.Json)
setBody(PostRandomRequest(listOf("Jet", "Brains")))
}
assertEquals("Hello World!", response.bodyAsText())
assertEquals(HttpStatusCode.Created, response.status)
Renaud
04/22/2022, 2:26 PMval client = createClient {
this@testApplication.install(ContentNegotiation)
...
But since I’m using HOCON config file, according to the doc:
Add modules automatically
If you have thefile in theapplication.conf
folder,resources
loads all modules and properties specified in the configuration file automatically.testApplication
phldavies
04/22/2022, 2:27 PMContentNegotiation
for the client, not the server versionimport io.ktor.client.plugins.contentnegotiation.ContentNegotiation
or
createClient {
install(io.ktor.client.plugins.contentnegotiation.ContentNegotiation)
}
Renaud
04/22/2022, 3:08 PM