C++ backend URL Routing

currently im writing this web app with my backend being in c++
basically after parsing the http request string I just have a bunch of conditional statements calling relevant "controllers" to handle actions

for example
  ...
  else if(req.URI == "/logout") {
      handle_logout(req, client_socket);
  }

  else if (req.URI.find("/search") == 0) {
      std::unordered_map<std::string, std::string> params = parse_parameters(req.URI);
      if (params.find("query") != params.end())
          handle_search(req, client_socket, params["query"]);
      else
          sendNotFoundResponse(client_socket);
  }
  ...etc


with controllers which are defined like bellow with some logic

void handle_logout(HTTPRequest& req, int client_socket);
void handle_search(HTTPRequest& req, int client_socket, std::string query);


rather than having an increasingly large if else tree for every route im thinking of something like this

class Router {
    std::unordered_map<std::string, std::unordered_map<std::string, std::function<void()>>> router {};
};

where
router[URL][http method] will store the relevant controller

now the major issue im having is not all controllers have the same number of arguments
would anyone be able to help me with a design for my router class to circumvent this?
Was this page helpful?