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 static std::string getMimeType(
const std::string &path);
198 std::function<
HandlerResponse(
const httplib::Request &, httplib::Response &)> preRoutingHandler();
200 std::function<void(
const httplib::Request &, httplib::Response &)> postRoutingHandler();
202 std::function<void(
const httplib::Request &, httplib::Response &)> optionsHandler();
204 std::function<void(
const httplib::Request &,
const httplib::Response &)> routingLogger();
206 std::function<void(
const httplib::Request &, httplib::Response &)> routingErrorHandler();
223 std::unique_ptr<SSEMgr> m_sseMgr;
225 std::vector<MiddlewareFn> m_preRoutingMiddlewares;
226 std::vector<HandlerFn> m_postRoutingMiddlewares;
227 std::unique_ptr<EntitySchema> m_entitySchema;
228 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:42
Wrapper around httplib::Response for consistent API.
Definition http.h:318
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:225
void removeSchemaCache(const std::string &entity_name)
Remove schema from cache.
Definition router.cpp:261
void Patch(const std::string &path, const HandlerWithContentReaderFn &handler, const Middlewares &middlewares={})
Register PATCH route with content reader (for file uploads).
Definition router.cpp:196
std::string decompressResponseBody(const std::string &body, const std::string &encoding)
Decompress response body based on encoding.
Definition router_httplib_internals.cpp:338
void close()
Close HTTP server and stop listening.
Definition router.cpp:155
void updateSchemaCache(const std::string &old_entity_name, const json &new_schema)
Update cached schema.
Definition router.cpp:246
const json & schemaCache(const std::string &table_name) const
Get cached schema JSON by table name.
Definition router.cpp:213
void Get(const std::string &path, const HandlerFn &handler, const Middlewares &middlewares={})
Register GET route.
Definition router.cpp:176
bool listen()
Start HTTP server and begin listening for connections.
Definition router.cpp:97
bool hasSchemaCache(const std::string &table_name) const
Check whether schema cache for given name exists.
Definition router.cpp:221
void Post(const std::string &path, const HandlerWithContentReaderFn &handler, const Middlewares &middlewares={})
Register POST route with content reader (for file uploads).
Definition router.cpp:182
Router()
Construct router instance.
Definition router.cpp:28
SSEMgr & sseMgr() const
Definition router.cpp:172
~Router()
Destructor.
Definition router.cpp:51
void Delete(const std::string &path, const HandlerFn &handler, const Middlewares &middlewares={})
Register DELETE route.
Definition router.cpp:208
httplib::Server & server()
Get underlying httplib::Server instance.
Definition router.cpp:168
bool init()
Initialize router: create system tables and admin routes.
Definition router.cpp:56
void addSchemaCache(const nlohmann::json &entity_schema)
Add schema to cache.
Definition router.cpp:233
Entity class for database table operations and CRUD functionality.
router.h
Definition auth.h:15
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.