can’t you just do ``` val result = client.get<H...
# ktor
m
can’t you just do
Copy code
val result = client.get<HttpResponse> { /* your code here */ }
val data = result.content.readRemaining().readText()
d
I am her the error at the .get method: "Suspend function "get" should be called only from a coroutine Or another suspend function. So I new in this Topic. Where I am looking for ist an method like: fun name(){...} which Call the Service and Chance one Attribute After that
m
Ah. You can wrap the
client.get
in a
runBlocking { }
, or you can make the call from a
suspend
function.
So your code would now be:
Copy code
val result = runBlocking {
    client.get<HttpResponse> { /* your code here */ }
}
val data = result.content.readRemaining().readText()
d
` val htmlContent = runBlocking{ client.get<HttpResponse>{ url { path("/inventory/start") } } } ´ Now I am get the error: "Exception in thread "main" java.lang.IncompatibleClassChangeError at kotlinx.coroutines.experimental.Job$DefaultImpls.invokeOnCompletion$default"
👀 1
e
Hi, @damian. What version of ktor do you use?
d
'0.9.2'
m
So this seems to work just fine for me:
Copy code
val data = runBlocking{
                            client.get<HttpResponse>{
                                url(URL("<https://www.google.com>"))
                            }.content.readRemaining().readText()
                        }
e
You could also just write:
client.get<String>("url")
It converts the response to string automatically
m
readRemaining()
is also a suspend function, so also needs to be in the
runBlocking {}
👌 1
Oh, sure, that would also work if that’s all you need from the response.
So yes, this would be more compact:
Copy code
val data = runBlocking{
  client.get<String>("<https://www.google.com>")
}
d
Yes, but I think the type is not the Problem. I have a brake point in my server, but I am never reach this (with postman or browser, this works). So the error occurs bevor sending the request.