Replies: 1 comment
-
In order to do this you will need to add a import URLRouting
import Foundation
enum AppRoute {
case foo(FooRoute)
}
enum FooRoute {
case id(String)
case bar(BarRoute)
}
enum BarRoute {
case id(String)
case zurg(String)
}
let idParser = Parse {
"id"
Parse(.string)
}
let barRouter = OneOf {
Route(.case(BarRoute.id)) {
Path { idParser }
}
Route(.case(BarRoute.zurg)) {
Path { "zurg"; idParser }
}
}
let fooRouter = OneOf {
Route(.case(FooRoute.id)) {
Path { idParser }
}
Route(.case(FooRoute.bar)) {
Path { "bar" }
barRouter
}
}
let appRouter = OneOf {
Route(.case(AppRoute.foo)) {
Path { "foo" }
fooRouter
}
}
/*
https://apps.apple.com/foo/bar/zurg/id409201541
https://apps.apple.com/foo/bar/id409201541
https://apps.apple.com/foo/id409201541
*/
var request = URLRequest(url: URL(string: "/foo/id409201541")!)
var requestData = URLRequestData(request: request)!
print(try appRouter.parse(requestData))
// oauth2(Oauth2Route.token(Oauth2Route.TokenInfo(grant_type: "authorization_code", client_id: "my_app", code: "deadbeef-deadbeef-dead-beef-dead-beefdeadbeef", redirect_uri: "my_app://auth", code_verifier: "deadbeef-deadbeef-dead")))
request = URLRequest(url: URL(string: "/foo/bar/id409201541")!)
requestData = URLRequestData(request: request)!
print(try appRouter.parse(requestData))
request = URLRequest(url: URL(string: "/foo/bar/zurg/id409201541")!)
requestData = URLRequestData(request: request)!
print(try appRouter.parse(requestData)) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I have encountered a problem in the process of using it and would like to ask for advice.
Here is the input:
https://apps.apple.com/xx/xx/xx/id{product_id}
or maybe:
https://apps.apple.com/xx/xx/id{product_id}
even:
https://apps.apple.com/xx/id{product_id}
I would like to know if there is a way to parse the product id in the link?
Thanks a lot.
Beta Was this translation helpful? Give feedback.
All reactions