https://kotlinlang.org logo
#ktor
Title
# ktor
b

Berkay Özkan

10/20/2023, 6:42 AM
Hi, what is the best way to get query parameter as list such as
/foo?ids=123,234,345
, also some requests come like this
/foo?ids=123&ids=234&ids=345
a

Aleksei Tirman [JB]

10/23/2023, 6:37 AM
Here is a function you can use to get a list of query parameter values:
Copy code
fun ApplicationRequest.getQueryList(name: String): List<String> {
    val result = mutableListOf<String>()
    (queryParameters.getAll(name) ?: emptyList()).forEach {
        result.addAll(it.split(','))
    }
    return result
}
🙏 1
b

Berkay Özkan

10/23/2023, 6:43 AM
i use something similar, i had wondered if there is better way. Thanks a lot