HI; Ktor (1.6.7) provides a url {} dsl to facilita...
# ktor
w
HI; Ktor (1.6.7) provides a url {} dsl to facilitate building new urls based on e.g. incoming requests, etc. Unfortunately, this only returns the url as String; would it be possible to allow returning a Url instead of the String ?
a
Could you please share a code snippet for clarifying your question?
w
Sure:
Copy code
val newUrl = url {
        path(language.name, areasTerm(language = language))
    }
always returns a String, which makes it hard to access e.g. just the full path of that Url instead everything. Right now I have to fall back to
Copy code
val url = URLBuilder(
        parameters = ParametersBuilder().apply {
            set(name = "verbund", value = verbund)
            set(name = "show", value = deriveToggleValue(sortOrder = sortOrder))
        }
    ).apply {
        path(language.name, areasTerm(language = language))
    }.build().fullPath
to be able to work with parts of the Url.
Does that make sense ?
a
Yes, it makes sense to UrlBuilder for your case. I think your code could be simplified to the following:
Copy code
val path = URLBuilder().apply {
    parameters["verbund"] = verbund
    parameters["show"] = deriveToggleValue(sortOrder = sortOrder)
    path(language.name, areasTerm(language = language))
}.build().fullPath
The
url
method is just a helper to build an URL and get it as String.
w
That’s m point sort of; it’s name is slightly mis-leading, as it doesn’t return a Url 😉
Given that it’s probably highly used, this won’t be easy/possible to change
But how about providing another helper method along the lines of buildUrl { .. } that retuns a Url instead of a String ?
a
Please file an issue if you want to see this method in Ktor.
w
Done