annotation accepts a path, not a full URL. You can use the DefaultRequest plugin to set the default URL for all requests.
c
Cương Nguyễn
10/14/2024, 2:04 PM
Thanks @Aleksei Tirman [JB] , how can I use 1 http client for multiple resources from mutiple host names. without Resource I can do it.
a
Aleksei Tirman [JB]
10/14/2024, 6:27 PM
You can configure
HttpRequestBuilder
for each request to set the appropriate host. Here is an example:
Copy code
@Resource("/get")
class Get()
suspend fun main() {
val client = HttpClient(CIO) {
install(Resources)
}
val response = client.get(Get()) {
url {
protocol = URLProtocol.HTTPS
host = "httpbin.org"
}
}
println(response.bodyAsText())
}
c
Cương Nguyễn
10/19/2024, 12:12 PM
I missed this one. I still have a small concern that I need to explicit specify the host ( which I believe is not “type-safe”. I can set a wrong host or forget to set host).
I still go with your suggestion. Thank you a lot for your help.