Replies: 3 comments 11 replies
-
Hi @addame2, because this is not a bug and more of a feature request or question about usage, I'm going to convert it to a discussion. Can you provide examples or links to the exact format you want to parse, and the exact data type you want to parse to? For example, what MongoDB library are you using? With that info, folks can try to help you cook up an appropriate parser. |
Beta Was this translation helpful? Give feedback.
-
I'm pursuing a similar goal. Get: room named 'zeus'
/rooms/zeus
struct RoomNameParser<Input: StringProtocol>: Parser where Input.SubSequence == Input {
func parse(_ path: inout Input) throws -> String {
guard let name = path.removingPercentEncoding else {
throw RoomNameParsingError.percentEncoding
}
guard name.rangeOfCharacter(from: .alphanumerics.inverted) == nil else {
throw RoomNameParsingError.invalidChars
}
guard RoomNameValidator(value: name).isValid else {
throw RoomNameParsingError.invalidCharLength
}
return name.lowercased()
}
}
extension RoomNameParser: ParserPrinter where Input: PrependableCollection {
func print(_ output: String, into input: inout Input) throws {
input.prepend(contentsOf: output)
}
}
extension String {
static func nameParser<Input>() -> RoomNameParser<Input> {
.init()
}
} In my route handler, I have this. Route(.case(RoomsRoute.room)) {
Path { String.nameParser() }
roomRoute
} All building fine, but.
Previously I had a UUID value instead of Route(.case(RoomsRoute.room)) {
Path { UUID.parser() }
roomRoute
} @stephencelis you have any guidance on why I'm getting |
Beta Was this translation helpful? Give feedback.
-
ObjectId is from mongo db
Beta Was this translation helpful? Give feedback.
All reactions