Trying to parse a URL into a Route enum #179
-
Hello :) I'm trying to parse an URL of the shape https://my.website.com/sign-in/mobile?token=SomeL0ngSequence0fChars&flow=sign-in so I tried the following enum AppRoute {
case signIn(token: String)
}
let router = OneOf {
Route(AppRoute.signIn(token:)) {
Path(FromUTF8View { "sign-in".utf8 })
Path(FromUTF8View { "mobile".utf8 })
Query("token", PrefixUpTo("&"))
Query("flow", "sign-in")
}
} where
I'm at a loss trying to understand what I'm doing wrong and how to fix it, and would greatly appreciate any help. Many thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@wtruppel That's a pretty bad error message 😞 The main issue is that Query("token", PrefixUpTo("&").map(String.init)) Please note, though, that query parsers are already split up to work on individual items, so the "&" character shouldn't be relevant at this point. I think you could instead do: Query("token", Rest().map(String.init)) |
Beta Was this translation helpful? Give feedback.
@wtruppel That's a pretty bad error message 😞
The main issue is that
PrefixUpTo
(and most parsers on strings) will output aSubstring
, so to bundle things up into your enum you must first convert the value back to a string:Please note, though, that query parsers are already split up to work on individual items, so the "&" character shouldn't be relevant at this point. I think you could instead do: