-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Named path parameters #1587
Comments
@bugdea1er I am not planning to support Is the following way enough in your case? srv.Get(R"(/projects/(\d+)/item)", [](auto req, auto res) {
auto id = req.matches[1];
}); |
@yhirose It will go as a temporary solution, but as for me, it’s more correct to catch all requests that match the URL, and only on the backend side decide whether this format is suitable or not (responding with "404 Project not found" for /projects/string) If you are ok with this, then you can leave the ticket open. Maybe someday I or someone else will throw a pull request on this topic. Also during these days, I also thought that named path parameters are also an interesting feature. |
@bugdea1er one of the possible problems to introduce the On my side, I am not planning to implement the feature since I am satisfied with the current regex way. Are you seriously thinking of implementing the feature in the near future? |
@yhirose we are planning to modify this library in our project to support such named parameters. I think we can try to support both old and new syntax and if we succeed we will send you a pr |
For now, the server is putting the responsibility on me to write the correct regex and duplicate it in every path. For example, it is not enough to use
(.+)
for project ID for pathsand
since it would also require to bind them to the server in the proper order.
I suggest to adopt some familiar syntax for parameters in paths (like,
{id}
or:id
) and do not require to write regexes from the user:srv.Get("/projects/{id}/item", handler);
Such syntax would also allow me to get parameter values by the key instead of the order with some kind of operator[]:
The text was updated successfully, but these errors were encountered: