-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add named path parameters parsing (Implements #1587) #1608
Conversation
@yhirose one of the possible solutions for this naming is to hide the new functions behind an optional compilation flag like you did with ssl support. I doubt that anyone would use both options for paths in the same project We want your opinion |
Great pull request! Indeed, the 'Simple' suffix might cause confusion among users. Personally, I would prefer to retain both the regex matcher and the path params matcher. How about checking at runtime whether the path includes inline Server &Server::Get(const std::string &pattern, Handler handler) {
auto matcher = pattern.find("/:") != std::string::npos
? detail::make_unique<detail::PathParamsMatcher>(pattern),
: detail::make_unique<detail::RegexMatcher>(pattern);
get_handlers_.push_back(std::make_pair(matcher, std::move(handler)));
return *this;
} By following the above approach, we can maintain just one |
Great idea! |
Or something like this? inline std::unique_ptr<detail::MatcherBase> Server::make_matcher(
const std::string &pattern) const {
return pattern.find("/:") != std::string::npos
? detail::make_unique<detail::PathParamsMatcher>(pattern),
: detail::make_unique<detail::RegexMatcher>(pattern);
}
inline Server &Server::Get(const std::string &pattern, Handler handler) {
get_handlers_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
return *this;
} Could you please also update README to show calling examples? Thanks a lot! |
Done. |
Thanks for the fine contribution! I believe many users will like the new feature. 👍 |
As discussed with @bugdea1er, I have implemented named path parameter parsing.
New parser is accessible by a different set of Get/Post/Put/Patch/Delete/Options methods with a suffix "Simple" (open for suggestions).
Example of usage from tests: