Is there a way to create a Url relative to another...
# ktor
Is there a way to create a Url relative to another Url? I have a URL: and another relative path:
but short of dissecting the URLs, there doesn’t seem to be a way to create one like there is in the JDK:
URL(URL("<>"), "/someotherpage")
Have you tried the BASE_URL strategy? I.e. set up constants in your codebase for different URLs, e.g.:
Copy code
const val BASE_URL = "<>"
const val PAGE_URL = "$BASE_URL/page"
const val SOME_OTHER_PAGE_URL = "$BASE_URL/someotherpage"
I'm parsing html, so I need to support generic urls
Could we do something similar in that case as well? i.e.
Copy code
val BASE_URL = fetchedUrl.substringBefore("/")
val PAGE_URL = BASE_URL + "/page"
And so on?
Yes, but at that point I'm just going to use the built in jvm classes. Just would prefer to use the cross platform ktor stuff. Seems like it's not supported
I'm not sure, maybe it is supported, these were just my 2 cents. Maybe someone more experienced should be able to help 👍
should do the trick