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/ahttp://localhost:8080/a/bhttp://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
enleur
10/23/2018, 11:49 AM
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] }
enleur
10/23/2018, 11:49 AM
it will give you a map
["a" => 1, "b" => 2, "c" => 3]
r
robin
10/23/2018, 11:51 AM
@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.