8#ifndef ROUTE_REGISTRY_H
9#define ROUTE_REGISTRY_H
12#include <unordered_map>
17#include <nlohmann/json.hpp>
19#include "../utils/utils.h"
44 std::variant<HandlerFn, HandlerWithContentReaderFn>
handler;
53 std::unordered_map<RouteKey, RouteHandler, RouteKeyHash> routes;
64 void add(
const std::string& method,
65 const std::string& path,
76 void add(
const std::string& method,
77 const std::string& path,
87 const RouteHandler*
find(
const std::string& method,
const std::string& path)
const;
96 json remove(
const std::string& method,
const std::string& path);
Definition route_registry.h:51
void add(const std::string &method, const std::string &path, HandlerFn handler, const Middlewares &middlewares)
Add new route to the registry.
Definition route_registry.cpp:17
const RouteHandler * find(const std::string &method, const std::string &path) const
Find a route in the registry matching given method and route.
Definition route_registry.cpp:33
json remove(const std::string &method, const std::string &path)
Remove find and remove existing route + path pair from the registry.
Definition route_registry.cpp:39
const std::string __class_name__
Definition route_registry.h:98
router.h
Definition auth.h:15
std::pair< Method, Path > RouteKey
Shorthand notation for the request's method, path pair.
Definition types.h:55
std::vector< MiddlewareFn > Middlewares
Middleware function arrays
Definition types.h:46
std::function< void(MantisRequest &, MantisResponse &, MantisContentReader &)> HandlerWithContentReaderFn
Route Handler function with content reader shorthand
Definition types.h:40
std::function< void(MantisRequest &, MantisResponse &)> HandlerFn
Route Handler function shorthand
Definition types.h:36
nlohmann::json json
Shorten JSON namespace.
Definition context_store.h:18
Struct encompassing the list of middlewares and the handler function registered to a specific route.
Definition route_registry.h:42
std::vector< MiddlewareFn > middlewares
Definition route_registry.h:43
std::variant< HandlerFn, HandlerWithContentReaderFn > handler
List of
Definition route_registry.h:44
Definition route_registry.h:29
size_t operator()(const RouteKey &k) const
Operator function called when hashing RouteKey is required.
Definition route_registry.cpp:12
Type definitions and aliases for MantisBase.