11#include <nlohmann/json.hpp>
16#include "../utils/utils.h"
183 void globalRouteHandler(
const std::string &method,
const std::string &path);
185 void globalRouteHandlerWithReader(
const std::string &method,
const std::string &path);
187 void generateMiscEndpoints();
189 void registerEntityRoutes();
191 void registerSchemaRoutes();
193 void registerAuthRoutes();
195 static std::string getMimeType(
const std::string &path);
204 std::function<
HandlerResponse(
const httplib::Request &, httplib::Response &)> preRoutingHandler();
206 std::function<void(
const httplib::Request &, httplib::Response &)> postRoutingHandler();
208 std::function<void(
const httplib::Request &, httplib::Response &)> optionsHandler();
210 std::function<void(
const httplib::Request &,
const httplib::Response &)> routingLogger();
212 std::function<void(
const httplib::Request &, httplib::Response &)> routingErrorHandler();
231 std::unique_ptr<SSEMgr> m_sseMgr;
232 std::vector<MiddlewareFn> m_preRoutingMiddlewares;
233 std::vector<HandlerFn> m_postRoutingMiddlewares;
234 std::unordered_map<std::string, Entity> m_entityMap;
Represents a database table/entity with schema and CRUD operations.
Definition entity.h:39
MantisBase entry point.
Definition mantisbase.h:40
A wrapper class around httplib::Request offering a consistent API and allowing for easy wrapper metho...
Definition http.h:39
Wrapper around httplib::Response for consistent API.
Definition http.h:315
Definition route_registry.h:51
HTTP router for managing routes and request handling.
Definition router.h:38
Entity schemaCacheEntity(const std::string &table_name) const
Get cached entity by table name.
Definition router.cpp:187
void removeSchemaCache(const std::string &entity_name)
Remove schema from cache.
Definition router.cpp:222
void Patch(const std::string &path, const HandlerWithContentReaderFn &handler, const Middlewares &middlewares={})
Register PATCH route with content reader (for file uploads).
Definition http.cpp:47
std::string decompressResponseBody(const std::string &body, const std::string &encoding)
Decompress response body based on encoding.
Definition router_httplib_internals.cpp:428
void close()
Close HTTP server and stop listening.
Definition router.cpp:154
void updateSchemaCache(const std::string &old_entity_name, const json &new_schema)
Update cached schema.
Definition router.cpp:207
const json & schemaCache(const std::string &table_name) const
Get cached schema JSON by table name.
Definition router.cpp:175
void Get(const std::string &path, const HandlerFn &handler, const Middlewares &middlewares={})
Register GET route.
Definition http.cpp:27
bool listen()
Start HTTP server and begin listening for connections.
Definition router.cpp:96
bool hasSchemaCache(const std::string &table_name) const
Check whether schema cache for given name exists.
Definition router.cpp:183
void Post(const std::string &path, const HandlerWithContentReaderFn &handler, const Middlewares &middlewares={})
Register POST route with content reader (for file uploads).
Definition http.cpp:33
Router()
Construct router instance.
Definition router.cpp:30
SSEMgr & sseMgr() const
Definition router.cpp:171
~Router()
Destructor.
Definition router.cpp:52
void Delete(const std::string &path, const HandlerFn &handler, const Middlewares &middlewares={})
Register DELETE route.
Definition http.cpp:59
httplib::Server & server()
Get underlying httplib::Server instance.
Definition router.cpp:167
bool init()
Initialize router: create system tables and admin routes.
Definition router.cpp:59
void addSchemaCache(const nlohmann::json &entity_schema)
Add schema to cache.
Definition router.cpp:195
Entity class for database table operations and CRUD functionality.
router.h
Definition auth.h:16
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
httplib::Server::HandlerResponse HandlerResponse
Definition types.h:33
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
Type definitions and aliases for MantisBase.