|
Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
|
The main application class for the Orbit Framework. More...
#include <App.hpp>
Public Member Functions | |
| App (const config::ServerConfig &config) | |
| Constructs a new App instance. | |
| ~App () | |
| App (const App &)=delete | |
| App & | operator= (const App &)=delete |
| void | on_error (routing::ErrorHandler handler) |
| Registers a global error handler for the application. | |
| App & | use (routing::Middleware m) |
| Registers a global middleware. | |
| App & | group (const std::string &prefix, std::function< void(routing::Router &)> callback) |
| Creates a route group with a specific prefix. | |
| routing::Router::RouteBuilder | route (const std::string &path, http::HttpMethod method=http::HttpMethod::GET) |
| Initiates a route builder for a specific path and method. | |
| App & | get (const std::string &path, routing::RouteHandler handler) |
| Registers a GET route. | |
| App & | get (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler) |
| Registers a GET route with middleware. | |
| App & | post (const std::string &path, routing::RouteHandler handler) |
| Registers a POST route. | |
| App & | post (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler) |
| Registers a POST route with middleware. | |
| App & | put (const std::string &path, routing::RouteHandler handler) |
| Registers a PUT route. | |
| App & | put (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler) |
| Registers a PUT route with middleware. | |
| App & | patch (const std::string &path, routing::RouteHandler handler) |
| Registers a PATCH route. | |
| App & | patch (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler) |
| Registers a PATCH route with middleware. | |
| App & | del (const std::string &path, routing::RouteHandler handler) |
| Registers a DELETE route. | |
| App & | del (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler) |
| Registers a DELETE route with middleware. | |
| App & | options (const std::string &path, routing::RouteHandler handler) |
| Registers an OPTIONS route. | |
| App & | options (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler) |
| Registers an OPTIONS route with middleware. | |
| template<typename Handler > | |
| App & | get (const std::string &path, Handler &&handler) |
| template<typename Handler > | |
| App & | get (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler) |
| template<typename Handler > | |
| App & | post (const std::string &path, Handler &&handler) |
| template<typename Handler > | |
| App & | post (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler) |
| template<typename Handler > | |
| App & | put (const std::string &path, Handler &&handler) |
| template<typename Handler > | |
| App & | put (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler) |
| template<typename Handler > | |
| App & | patch (const std::string &path, Handler &&handler) |
| template<typename Handler > | |
| App & | patch (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler) |
| template<typename Handler > | |
| App & | del (const std::string &path, Handler &&handler) |
| template<typename Handler > | |
| App & | del (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler) |
| template<typename Handler > | |
| App & | options (const std::string &path, Handler &&handler) |
| template<typename Handler > | |
| App & | options (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler) |
| App & | ws (const std::string &path, routing::WsHandler handler) |
| Registers a WebSocket route. | |
| concurrency::ThreadPool & | get_thread_pool () |
| Retrieves the application's thread pool. | |
| App & | enable_metrics (const std::string &path="/metrics") |
| Enables Prometheus metrics endpoint. | |
| App & | enable_openapi (const std::string &title="Orbit Framework API", const std::string &version="1.0.0", const std::string &docs_path="/docs", const std::string &json_path="/swagger.json") |
| Enables OpenAPI documentation and Swagger UI. | |
| void | listen () |
| Starts the server and blocks the current thread. | |
| void | stop () |
| Gracefully stops the server. | |
| void | hot_reload () |
| Triggers a hot reload of the server configuration and routes. | |
The main application class for the Orbit Framework.
The App class acts as the central orchestrator for the web framework. It manages the server's lifecycle, routing, middlewares, dependency injection, and worker thread pools. Users instantiate this class, define their routes, and call listen() to start accepting connections.
| server::App::App | ( | const config::ServerConfig & | config | ) |
Constructs a new App instance.
| config | The server configuration containing port, worker threads, and event engine preferences. |
| server::App::~App | ( | ) |
|
delete |
|
inline |
| App & server::App::del | ( | const std::string & | path, |
| routing::RouteHandler | handler | ||
| ) |
Registers a DELETE route.
| path | The URL path. |
| handler | The route handler function. |
|
inline |
| App & server::App::del | ( | const std::string & | path, |
| std::vector< routing::Middleware > | mws, | ||
| routing::RouteHandler | handler | ||
| ) |
Registers a DELETE route with middleware.
| path | The URL path. |
| mws | A vector of middlewares to apply. |
| handler | The route handler function. |
| App & server::App::enable_metrics | ( | const std::string & | path = "/metrics" | ) |
Enables Prometheus metrics endpoint.
| path | The URL path for metrics (default is "/metrics"). |
| App & server::App::enable_openapi | ( | const std::string & | title = "Orbit Framework API", |
| const std::string & | version = "1.0.0", |
||
| const std::string & | docs_path = "/docs", |
||
| const std::string & | json_path = "/swagger.json" |
||
| ) |
Enables OpenAPI documentation and Swagger UI.
| title | The API title. |
| version | The API version. |
| docs_path | The URL path for Swagger UI. |
| json_path | The URL path for the OpenAPI JSON. |
|
inline |
| App & server::App::get | ( | const std::string & | path, |
| routing::RouteHandler | handler | ||
| ) |
Registers a GET route.
| path | The URL path. |
| handler | The route handler function. |
|
inline |
| App & server::App::get | ( | const std::string & | path, |
| std::vector< routing::Middleware > | mws, | ||
| routing::RouteHandler | handler | ||
| ) |
Registers a GET route with middleware.
| path | The URL path. |
| mws | A vector of middlewares to apply. |
| handler | The route handler function. |
|
inline |
Retrieves the application's thread pool.
| std::runtime_error | If the server is not started. |
|
inline |
Creates a route group with a specific prefix.
| prefix | The URL prefix for the group. |
| callback | A function to configure routes within the group. |
| void server::App::hot_reload | ( | ) |
Triggers a hot reload of the server configuration and routes.
| void server::App::listen | ( | ) |
Starts the server and blocks the current thread.
| void server::App::on_error | ( | routing::ErrorHandler | handler | ) |
Registers a global error handler for the application.
| handler | The error handler function. |
|
inline |
| App & server::App::options | ( | const std::string & | path, |
| routing::RouteHandler | handler | ||
| ) |
Registers an OPTIONS route.
| path | The URL path. |
| handler | The route handler function. |
|
inline |
| App & server::App::options | ( | const std::string & | path, |
| std::vector< routing::Middleware > | mws, | ||
| routing::RouteHandler | handler | ||
| ) |
Registers an OPTIONS route with middleware.
| path | The URL path. |
| mws | A vector of middlewares to apply. |
| handler | The route handler function. |
|
inline |
| App & server::App::patch | ( | const std::string & | path, |
| routing::RouteHandler | handler | ||
| ) |
Registers a PATCH route.
| path | The URL path. |
| handler | The route handler function. |
|
inline |
| App & server::App::patch | ( | const std::string & | path, |
| std::vector< routing::Middleware > | mws, | ||
| routing::RouteHandler | handler | ||
| ) |
Registers a PATCH route with middleware.
| path | The URL path. |
| mws | A vector of middlewares to apply. |
| handler | The route handler function. |
|
inline |
| App & server::App::post | ( | const std::string & | path, |
| routing::RouteHandler | handler | ||
| ) |
Registers a POST route.
| path | The URL path. |
| handler | The route handler function. |
|
inline |
| App & server::App::post | ( | const std::string & | path, |
| std::vector< routing::Middleware > | mws, | ||
| routing::RouteHandler | handler | ||
| ) |
Registers a POST route with middleware.
| path | The URL path. |
| mws | A vector of middlewares to apply. |
| handler | The route handler function. |
|
inline |
| App & server::App::put | ( | const std::string & | path, |
| routing::RouteHandler | handler | ||
| ) |
Registers a PUT route.
| path | The URL path. |
| handler | The route handler function. |
|
inline |
| App & server::App::put | ( | const std::string & | path, |
| std::vector< routing::Middleware > | mws, | ||
| routing::RouteHandler | handler | ||
| ) |
Registers a PUT route with middleware.
| path | The URL path. |
| mws | A vector of middlewares to apply. |
| handler | The route handler function. |
|
inline |
Initiates a route builder for a specific path and method.
| path | The URL path. |
| method | The HTTP method (default is GET). |
| void server::App::stop | ( | ) |
Gracefully stops the server.
| App & server::App::use | ( | routing::Middleware | m | ) |
Registers a global middleware.
| m | The middleware function. |
|
inline |
Registers a WebSocket route.
| path | The URL path. |
| handler | The WebSocket handler function. |