Hey guys. I think I found a inconsistent behaviour...
# ktor
x
Hey guys. I think I found a inconsistent behaviour with the
defaultRequest
plugin When you set a url with no trailing slash, the plugin adds it to the request for me. Which is fine 👍
Copy code
val baseUrl = "<https://api.github.com>" // No trailing slash
val client = HttpClient { defaultRequest { url(baseUrl) }
client.get("users") // REQUEST -> <https://api.github.com/users>
However, if there are additional path segments, it strips the last one off and adds trailing slash, malforming my url, which is bad 👎
Copy code
val baseUrl = "<https://api.github.com/api/v1>" // No trailing slash + extra path segments 
val client = HttpClient { defaultRequest { url(baseUrl) }
client.get("users") // REQUEST -> <https://api.github.com/api/users>
Note how the
v1
is removed from the request outbound I would expect it to return
<https://api.github.com/api/v1/users>
instead Is this the expected behaviour? or a bug?
e
that's how relative urls work on web
x
is it normal to remove the last segment if it is not suffixed with a
/
?
e
yes
x
Thanks. Didn't realise there was a convention for this.
k
TIL this too😅