4using namespace std::placeholders;
13#include <absl/hash/hash.h>
14#include <absl/container/flat_hash_map.h>
36 virtual ~Base() =
default;
39 template<
typename... Args>
40 struct Wrapper :
public Base
42 Wrapper(std::function<asio::awaitable<http::Response>(Args...)> func)
43 : function(std::move(func))
46 std::function<asio::awaitable<http::Response>(Args...)> function;
51 template<
typename... Args>
53 : _base(std::make_unique<Wrapper<Args...>>(std::move(func)))
58 template<
typename... Args>
59 asio::awaitable<http::Response>
operator()(Args && ... args)
const
61 Wrapper<Args...>* wrapper_ptr =
dynamic_cast<Wrapper<Args...
>*>(_base.get());
65 co_return co_await wrapper_ptr->function(std::forward<Args>(args)...);
69 throw std::runtime_error(
"Invalid arguments to function object call!");
74 std::unique_ptr<Base> _base;
95 const std::string & module_path,
96 const std::vector<std::string> & request_path_info_segments,
97 const absl::flat_hash_map<std::string, std::string> request_query_segments)
const;
100 absl::flat_hash_map<RouteKey, RouteHandlerFunc> _routes;
A class representing a route handler function.
Definition route.hpp:31
asio::awaitable< http::Response > operator()(Args &&... args) const
Definition route.hpp:59
RouteHandlerFunc(std::function< asio::awaitable< http::Response >(Args...)> func)
Definition route.hpp:52
RouteHandlerFunc(RouteHandlerFunc &&other)=default
A class representing a route key, which is a combination of a HTTP method and a URL.
Definition route_key.hpp:20
A class representing a router for handling HTTP requests.
Definition route.hpp:83
std::tuple< bool, std::vector< RouteArg >, QueryArgsList > doesRouteMatch(const RouteKey &route, const http::Method &request_method, const std::string &module_path, const std::vector< std::string > &request_path_info_segments, const absl::flat_hash_map< std::string, std::string > request_query_segments) const
Definition route.cpp:5
void addRoute(RouteKey route, RouteHandlerFunc handler)
Definition route.cpp:153
std::tuple< const RouteHandlerFunc *, std::vector< RouteArg >, QueryArgsList > findRoute(const http::Request &request) const
Definition route.cpp:122
Method
Enum to represent the request method.
Definition http_method.hpp:31
absl::flat_hash_map< std::string, RouteArg > QueryArgsList
Definition route.hpp:23