rrva
12/14/2019, 3:21 PMimport com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.features.json.JacksonSerializer
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.request.header
import io.ktor.client.request.parameter
import io.ktor.client.request.request
import io.ktor.client.request.url
class FooApiClient(val fooApiUrl: String, val objectMapper: ObjectMapper, val userAgent: String) {
val client = HttpClient(CIO) {
install(JsonFeature) {
serializer = JacksonSerializer { objectMapper }
}
}
suspend fun search(
q: String
): FooApiResponse {
return client.request {
header("User-Agent", userAgent)
parameter("q", q)
url(fooApiUrl)
}
}
}
Which gives exception:
No transformation found: class <http://kotlinx.coroutines.io|kotlinx.coroutines.io>.ByteBufferChannel -> class FooApiResponse
io.ktor.client.call.NoTransformationFoundException: No transformation found: class <http://kotlinx.coroutines.io|kotlinx.coroutines.io>.ByteBufferChannel -> class FooApiResponse
at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:88)