Hi, I am new to this channel, have a very basic qu...
# ktor
n
Hi, I am new to this channel, have a very basic question if anyone could help. I plan to create a generic route for all my GET requests which would allow requests like http://localhost:8080/a http://localhost:8080/a/b http://localhost:8080/a/b/c/././././ As of now I have 3 levels of hierarchy and I am handling it like this: routing { get("/*") { //logic } get("/(STAR HERE)/*") { //logic } get("/(* HERE)/(STAR HERE) /*") { //logic } } I have something similar for posts, and the hierarchies are expected to grow. Thank you.
e
just catch route by wildcard and transform rest of the route to params
Copy code
val str = "/a/1/c/2/e/3"

    val params = str.trim('/')
        .split("/")
        .windowed(2, 2)
        .associate { it[0] to it[1] }
it will give you a map
["a" => 1, "b" => 2, "c" => 3]
r
@enleur I guess their question is how to catch the route by wildcards without specifying every level of the hierarchy.
get("/*")
will not be triggered by a call to a url that has a second segment.
✔️ 1
e
Copy code
get("/trololo/{...}")
should work
or even
Copy code
get("/trololo/{param...}")
👍 1
n
Thank you for the response, I will check and update
{...} worked.. thanks a lot
👍 1