Osman Saral
12/24/2021, 10:34 PMdefautlRequest
for some requests?defaultRequest {
url {
protocol = URLProtocol.HTTPS
host = "<http://myapi.com|myapi.com>"
}
}
But we have to send a request to a different host for only single endpoint. I've tried to do this, but defautlRequest overrides the host.
suspend fun HttpClient.getOther(): Other = get("<https://example.com/other>")
it sends request to <https://myapi.com/other>
(it appends the path)Big Chungus
12/24/2021, 11:41 PMOsman Saral
12/25/2021, 11:52 AMBig Chungus
12/25/2021, 11:53 AMOsman Saral
12/25/2021, 11:56 AMBig Chungus
12/25/2021, 11:56 AMOsman Saral
12/25/2021, 12:01 PMBig Chungus
12/25/2021, 12:03 PMOsman Saral
12/25/2021, 12:06 PMdefaultRequest {
url {
protocol = URLProtocol.HTTPS
host = "<http://myapi.com|myapi.com>"
encodedPath = "apiPath$encodedPath"
}
}
And I have an extension function to define my endpoints.
suspend fun HttpClient.getOther(): Other = get("<https://example.com/other>")
request is sent to <https://myapi.com/apiPath/other>
Big Chungus
12/25/2021, 12:07 PMOsman Saral
12/25/2021, 12:07 PMBig Chungus
12/25/2021, 12:08 PMOsman Saral
12/25/2021, 12:09 PMsuspend fun HttpClient.getOther(): Other = get {
url {
host = "<http://example.com|example.com>"
path("other")
}
}
suspend fun HttpClient.getOther(): Other = get {
host = "<http://example.com|example.com>"
url {
path("other")
}
}
Big Chungus
12/25/2021, 12:12 PMOsman Saral
12/25/2021, 1:37 PMBig Chungus
12/25/2021, 1:42 PMOsman Saral
12/25/2021, 1:43 PM