Parsing String parameter in path. #2
-
Hey! Thanks for putting together this library, I'm keen to start using it straight away! However I've hit a roadblock that I've been not been able to resolve whilst digging through the documentation. In your example scenario if the enum argument is an alphanumeric enum AppRoute {
case buyBook(id: String)
}
let appRouter = OneOf {
// GET /books/:id/buy
Route(.case(AppRoute.buyBook(id:))) {
Path { "books"; /* Parse printer??? */ "buy" }
}
} I've attempted to use Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@sean-howard You can use Route(.case(AppRoute.buyBook(id:))) {
Path { "books"; Parse(.string); "buy" }
} And if you use a struct BookId: RawRepresentable {
var rawValue: String
}
enum AppRoute {
case buyBook(id: BookId)
}
let appRouter = OneOf {
// GET /books/:id/buy
Route(.case(AppRoute.buyBook(id:))) {
Path { "books"; Parse(.string.representing(BookId.self); "buy" }
}
} |
Beta Was this translation helpful? Give feedback.
@sean-howard You can use
Parse(.string)
to peel off an entire path component:And if you use a
RawRepresentable
type-safe wrapper for the ID, you can use.string.representing(BookId.self)
: