HTTP router for managing routes and request handling.
More...
#include <router.h>
|
| | Router () |
| | Construct router instance.
|
| |
| | ~Router () |
| | Destructor.
|
| |
| bool | init () |
| | Initialize router: create system tables and admin routes.
|
| |
| bool | listen () |
| | Start HTTP server and begin listening for connections.
|
| |
| void | close () |
| | Close HTTP server and stop listening.
|
| |
| httplib::Server & | server () |
| | Get underlying httplib::Server instance.
|
| |
| SSEMgr & | sseMgr () const |
| |
| void | Get (const std::string &path, const HandlerFn &handler, const Middlewares &middlewares={}) |
| | Register GET route.
|
| |
| void | Post (const std::string &path, const HandlerWithContentReaderFn &handler, const Middlewares &middlewares={}) |
| | Register POST route with content reader (for file uploads).
|
| |
| void | Post (const std::string &path, const HandlerFn &handler, const Middlewares &middlewares={}) |
| | Register POST route.
|
| |
| void | Patch (const std::string &path, const HandlerWithContentReaderFn &handler, const Middlewares &middlewares={}) |
| | Register PATCH route with content reader (for file uploads).
|
| |
| void | Patch (const std::string &path, const HandlerFn &handler, const Middlewares &middlewares={}) |
| | Register PATCH route.
|
| |
| void | Delete (const std::string &path, const HandlerFn &handler, const Middlewares &middlewares={}) |
| | Register DELETE route.
|
| |
| const json & | schemaCache (const std::string &table_name) const |
| | Get cached schema JSON by table name.
|
| |
| bool | hasSchemaCache (const std::string &table_name) const |
| | Check whether schema cache for given name exists.
|
| |
| Entity | schemaCacheEntity (const std::string &table_name) const |
| | Get cached entity by table name.
|
| |
| void | addSchemaCache (const nlohmann::json &entity_schema) |
| | Add schema to cache.
|
| |
| void | updateSchemaCache (const std::string &old_entity_name, const json &new_schema) |
| | Update cached schema.
|
| |
| void | removeSchemaCache (const std::string &entity_name) |
| | Remove schema from cache.
|
| |
| std::string | decompressResponseBody (const std::string &body, const std::string &encoding) |
| | Decompress response body based on encoding.
|
| |
HTTP router for managing routes and request handling.
Router provides methods to register HTTP routes with handlers and middlewares, manages entity schema cache, and handles request routing.
});
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
void sendJSON(int statusCode=200, const json &data=json::object()) const
Send JSON response.
Definition http_response.cpp:145
std::function< HandlerResponse(MantisRequest &, MantisResponse &)> requireAdminAuth()
Require admin authentication.
Definition middlewares.cpp:299
◆ Router()
Construct router instance.
◆ ~Router()
◆ addSchemaCache()
| void mb::Router::addSchemaCache |
( |
const nlohmann::json & |
entity_schema | ) |
|
Add schema to cache.
- Parameters
-
| entity_schema | Schema JSON to cache |
◆ close()
| void mb::Router::close |
( |
| ) |
|
Close HTTP server and stop listening.
◆ decompressResponseBody()
| std::string mb::Router::decompressResponseBody |
( |
const std::string & |
body, |
|
|
const std::string & |
encoding |
|
) |
| |
Decompress response body based on encoding.
- Parameters
-
| body | Compressed body data |
| encoding | Encoding type (e.g., "gzip", "deflate") |
- Returns
- Decompressed body string
◆ Delete()
| void mb::Router::Delete |
( |
const std::string & |
path, |
|
|
const HandlerFn & |
handler, |
|
|
const Middlewares & |
middlewares = {} |
|
) |
| |
Register DELETE route.
- Parameters
-
| path | Route path |
| handler | Request handler function |
| middlewares | Optional middleware functions |
◆ Get()
| void mb::Router::Get |
( |
const std::string & |
path, |
|
|
const HandlerFn & |
handler, |
|
|
const Middlewares & |
middlewares = {} |
|
) |
| |
Register GET route.
- Parameters
-
| path | Route path (supports path parameters like /:id) |
| handler | Request handler function |
| middlewares | Optional middleware functions
});
std::string getPathParamValue(const std::string &key) const Get path parameter value. Definition http_request.cpp:109
|
◆ hasSchemaCache()
| bool mb::Router::hasSchemaCache |
( |
const std::string & |
table_name | ) |
const |
Check whether schema cache for given name exists.
- Parameters
-
| table_name | Table name to lookup |
- Returns
- true if found, false otherwise.
◆ init()
| bool mb::Router::init |
( |
| ) |
|
Initialize router: create system tables and admin routes.
- Returns
- true if initialization successful
◆ listen()
| bool mb::Router::listen |
( |
| ) |
|
Start HTTP server and begin listening for connections.
- Returns
- true if server started successfully
◆ Patch() [1/2]
| void mb::Router::Patch |
( |
const std::string & |
path, |
|
|
const HandlerFn & |
handler, |
|
|
const Middlewares & |
middlewares = {} |
|
) |
| |
Register PATCH route.
- Parameters
-
| path | Route path |
| handler | Request handler function |
| middlewares | Optional middleware functions |
◆ Patch() [2/2]
Register PATCH route with content reader (for file uploads).
- Parameters
-
| path | Route path |
| handler | Handler with content reader |
| middlewares | Optional middleware functions |
◆ Post() [1/2]
| void mb::Router::Post |
( |
const std::string & |
path, |
|
|
const HandlerFn & |
handler, |
|
|
const Middlewares & |
middlewares = {} |
|
) |
| |
Register POST route.
- Parameters
-
| path | Route path |
| handler | Request handler function |
| middlewares | Optional middleware functions |
◆ Post() [2/2]
Register POST route with content reader (for file uploads).
- Parameters
-
| path | Route path |
| handler | Handler with content reader for multipart/form-data |
| middlewares | Optional middleware functions |
◆ removeSchemaCache()
| void mb::Router::removeSchemaCache |
( |
const std::string & |
entity_name | ) |
|
Remove schema from cache.
- Parameters
-
| entity_name | Table name to remove |
◆ schemaCache()
| const json & mb::Router::schemaCache |
( |
const std::string & |
table_name | ) |
const |
Get cached schema JSON by table name.
- Parameters
-
| table_name | Table name to lookup |
- Returns
- Reference to cached schema JSON
◆ schemaCacheEntity()
| Entity mb::Router::schemaCacheEntity |
( |
const std::string & |
table_name | ) |
const |
Get cached entity by table name.
- Parameters
-
| table_name | Table name to lookup |
- Returns
- Entity instance from cache
◆ server()
| httplib::Server & mb::Router::server |
( |
| ) |
|
Get underlying httplib::Server instance.
- Returns
- Reference to HTTP server
◆ sseMgr()
| SSEMgr & mb::Router::sseMgr |
( |
| ) |
const |
◆ updateSchemaCache()
| void mb::Router::updateSchemaCache |
( |
const std::string & |
old_entity_name, |
|
|
const json & |
new_schema |
|
) |
| |
Update cached schema.
- Parameters
-
| old_entity_name | Old table name |
| new_schema | Updated schema JSON |
The documentation for this class was generated from the following files: