Hi! In my current Android project I need the ability to change server base url in runtime through UI. How can I change base request url asynchronously?
Preferably I want to use it something like this:
Copy code
class KtorClientFactory(
private val baseUrl: suspend () -> String,
) {
fun create(): HttpClient = HttpClient(
engine = OkHttpEngine(config = OkHttpConfig())
) {
installDefaultRequest()
}
private fun HttpClientConfig<*>.installDefaultRequest() {
install(DefaultRequest) {
url {
host = baseUrl() // Can't call suspend here. Want it to be called on each request
}
}
}
}