Hello! I’m using KtorClient in Kotlin/JS and I’m ...
# ktor
r
Hello! I’m using KtorClient in Kotlin/JS and I’m having some troubles. I’m making a simple playground project where I make a request to: https://catfact.ninja/fact but it’s throwing me the following error in console
Copy code
"No transformation found: class ByteChannelJS -> class Fact
with response from <https://catfact.ninja/fact>:
status: 200 
response headers: 
cache-control: no-cache, private
, content-type: application/json"
More in 🧵 Edit: Solved . Check thread if you want to laugh 😭
😅 2
This is the JS client
Copy code
val client = HttpClient(Js) {
    install(Resources)

    install(ContentNegotiation) {
        Json {
            prettyPrint = true
            isLenient = true
            ignoreUnknownKeys = true
        }
    }
}
The request:
Copy code
val fact: Fact = client.get("<https://catfact.ninja/fact>").body<Fact>()
And the data class
Copy code
@Serializable
data class Fact(val fact: String)
I feel like everything is in place but I don’t know if i’m missing something. I’ve re-read the docs over and over and still can’t find the issue By any chance, do you see something’s off or what could be missing?
My understanding on the issue being thrown is that it can’t parse/transform the json coming from the server to my data class. But I have serializable added to my module and my data class, plus I’ve added
Json
to my client content negotiation. So how is that it doesn’t know how to transform it?
Just in case you want to know my dependencies:
Ah nvm, I just realized I’m not registering the content-type. I was just writing the
Json
on my IDE and doing nothing. Now the issue is solved, spent 3 hours on this bloodtrail
Copy code
val client = HttpClient(Js) {
    install(Resources)

    install(ContentNegotiation) {
        json(
            Json {
                prettyPrint = true
                isLenient = true
                ignoreUnknownKeys = true
            }
        )
    }
}
a
I've made this same mistake before but on the server... 😅
😂 2