When using Ktor client for consuimg REST API as fa...
# ktor
v
When using Ktor client for consuimg REST API as far as I understand
Copy code
val status = HttpClient().use { client ->
    // ...
}
should be preferred to
Copy code
client.get("<https://ktor.io/>")
So there is no need to call the
.close()
function
👌 1
a
Although it will be resource consuming if you create an HTTP client for each request.
1
v
Oh yeah of course not, the client will be passed to the constructor of the API, this was just an example
This doesn’t work tho, after the first request I get Parent job is Completed;
a
Please share a code snippet.
v
image.png
a
Could you please share a complete code snippet as text to reproduce your problem?
b
https://ktor.io/docs/client.html#close-client with this code, you need to recreate the HttpClient for each request
after close execution and completion of all requests (which started before calling close) - threads are stopped, closed coroutines scopes etc.
👍 1
v
Yeah makes sense, I assume it’s not a good idea to create a new client for each request, but use the same one application wide