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

degreat

09/19/2020, 2:21 PM
How do I make this locations match? The first should match alphanumeric, and the second should match integers
l

louiscad

09/20/2020, 6:27 AM
Is there a way to define priority?
m

Matteo Mirk

09/21/2020, 12:50 PM
I’m just guessing here: probably to Ktor a String path variable will match everything, so it stops. Maybe declaring the {id} first will make it try to parse an integer and pass to the next if it fails… but yeah it’s not a robust way.
d

degreat

09/21/2020, 12:54 PM
I tired that, but didn't work
🙁 1
It didn't work for both cases
If I switch positions, the second match fails
m

Matteo Mirk

09/21/2020, 12:58 PM
perhaps this is the feature that could help you: https://ktor.io/docs/routing.html#extensibility
sorry I missed a sentence:
Path parsing is not extensible.
😞
d

degreat

09/21/2020, 1:01 PM
Alright thanks, I'll try that and let you know the outcome
Thanks very much
m

Matteo Mirk

09/21/2020, 1:04 PM
I’m starting to suspect that the only way to solve this is to match a generic {id} path and inside the routing function have a factory create either SlugOne or IdOne depending on a regex. Maybe it’s solvable only by code…
you’re welcome, let us know if you make it!
d

degreat

09/21/2020, 6:03 PM
@Matteo Mirk have a look at the trace
It says lost in ambiguity tie
And then there's stack trace that, it cannot convert the string into an integer
So an approach by the ktor team, imo, should be instead of throwing away ambiguity ties, it should be kept just in case a first match raises a parse/deserialization error
Until it's resolved, this is what I settled with. Probably this weekend I may try to solve the
Locations
approach and submit an MR
👍 1
m

Matteo Mirk

09/22/2020, 7:59 AM
Cool, that’s probably the only way to solve it for now. My knowledge stops a the trace, I’d have to dig into the path matching code to understand what’s going on. We should really need an authoritative voice from the Ktor team, but no one has answered so far… Maybe open an issue on Ktor repo and see what they say. Thanks for updating me!
d

degreat

09/22/2020, 10:16 PM
I already created the issue, but there is no response yet.
👍 1
m

Matteo Mirk

09/23/2020, 7:50 AM
Don’t lose hope, maybe they’ll get to it. Can you share the issue link, I could vote on it, if it helps
d

degreat

09/24/2020, 12:27 PM
Haha, thanks.
m

Matteo Mirk

09/24/2020, 1:20 PM
d

degreat

09/24/2020, 10:01 PM
this is great. Really appreciate the effort. I'll try and provide a fix and submit a merge request.. and hope they merge it in
🤟 1
🚀 1
6 Views