MantisBase v0.4.9
Loading...
Searching...
No Matches
route_registry.h
Go to the documentation of this file.
1
8
9#ifndef ROUTE_REGISTRY_H
10#define ROUTE_REGISTRY_H
11
12#include <unordered_map>
13#include <functional>
14#include <string>
15#include <vector>
16#include <nlohmann/json.hpp>
17
18#include "../utils/utils.h"
19#include "types.h"
20#include "logger/logger.h"
21
22namespace mb
23{
26 {
27 size_t operator()(const MbRouteKey& k) const;
28 };
29
32 {
33 std::vector<MbMiddlewareFn> middlewares;
35 };
36
41 {
42 std::unordered_map<MbRouteKey, MbRouteHandler, MbRouteKeyHash> routes;
43
44 public:
46 void add(const std::string& method,
47 const std::string& path,
48 const MbHandlerFn &handler,
49 const MbMiddlewares& middlewares);
50
52 const MbRouteHandler* find(const std::string& method, const std::string& path) const;
53
58 json remove(const std::string& method, const std::string& path);
59
63 void clear() {
64 routes.clear();
65 }
66 };
67}
68
69#endif // ROUTE_REGISTRY_H
Thread-local route registry backing the MantisBase router.
Definition route_registry.h:41
void clear()
Definition route_registry.h:63
const MbRouteHandler * find(const std::string &method, const std::string &path) const
Definition route_registry.cpp:19
json remove(const std::string &method, const std::string &path)
Remove a route from the registry.
Definition route_registry.cpp:24
void add(const std::string &method, const std::string &path, const MbHandlerFn &handler, const MbMiddlewares &middlewares)
Definition route_registry.cpp:12
#define MANTISBASE_API
Definition export.h:31
Structured logging wrapper around spdlog with optional SQLite persistence.
Definition api_keys.h:35
std::vector< MbMiddlewareFn > MbMiddlewares
Definition types.h:66
nlohmann::json json
Shorten JSON namespace.
Definition api_keys.h:36
std::function< void(MbRequest &, MbResponse &)> MbHandlerFn
Standard route handler (request, response).
Definition types.h:64
std::pair< MbMethod, MbPath > MbRouteKey
Route lookup key: HTTP method + path pattern.
Definition types.h:73
Definition route_registry.h:32
std::vector< MbMiddlewareFn > middlewares
Definition route_registry.h:33
MbHandlerFn handler
Definition route_registry.h:34
Definition route_registry.h:26
size_t operator()(const MbRouteKey &k) const
Definition route_registry.cpp:8
Core type aliases, handler signatures, and the MbAppMixin DI mixin.
Collection of utility functions that are re-used across different files.