Skip to content
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

Use matches property in ApiDispatcher regex #862

Open
zpalmtree opened this issue Aug 7, 2019 · 0 comments

Comments

@zpalmtree
Copy link
Collaborator

commented Aug 7, 2019

Some calls in the ApiDispatcher use a regex, for example, getTransactionDetails. They then extract the query parameters like so:

std::tuple<Error, uint16_t> ApiDispatcher::getTransactionDetails(
    const httplib::Request &req,
    httplib::Response &res,
    const nlohmann::json &body) const
{
    std::string hashStr = req.path.substr(std::string("/transactions/hash/").size());

We could instead extract hashStr using the matches property on the req object, by adding a capture group to the hash regex. Once this is done, the code would be something like

std::tuple<Error, uint16_t> ApiDispatcher::getTransactionDetails(
    const httplib::Request &req,
    httplib::Response &res,
    const nlohmann::json &body) const
{
    std::string hashStr = req.matches[0];

It is not much of a gain in readability here, but there are some methods which have multiple parameters needing to be extracted which would benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.