Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
server::App Class Reference

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
 
Appoperator= (const App &)=delete
 
void on_error (routing::ErrorHandler handler)
 Registers a global error handler for the application.
 
Appuse (routing::Middleware m)
 Registers a global middleware.
 
Appgroup (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.
 
Appget (const std::string &path, routing::RouteHandler handler)
 Registers a GET route.
 
Appget (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler)
 Registers a GET route with middleware.
 
Apppost (const std::string &path, routing::RouteHandler handler)
 Registers a POST route.
 
Apppost (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler)
 Registers a POST route with middleware.
 
Appput (const std::string &path, routing::RouteHandler handler)
 Registers a PUT route.
 
Appput (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler)
 Registers a PUT route with middleware.
 
Apppatch (const std::string &path, routing::RouteHandler handler)
 Registers a PATCH route.
 
Apppatch (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler)
 Registers a PATCH route with middleware.
 
Appdel (const std::string &path, routing::RouteHandler handler)
 Registers a DELETE route.
 
Appdel (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler)
 Registers a DELETE route with middleware.
 
Appoptions (const std::string &path, routing::RouteHandler handler)
 Registers an OPTIONS route.
 
Appoptions (const std::string &path, std::vector< routing::Middleware > mws, routing::RouteHandler handler)
 Registers an OPTIONS route with middleware.
 
template<typename Handler >
Appget (const std::string &path, Handler &&handler)
 
template<typename Handler >
Appget (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler)
 
template<typename Handler >
Apppost (const std::string &path, Handler &&handler)
 
template<typename Handler >
Apppost (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler)
 
template<typename Handler >
Appput (const std::string &path, Handler &&handler)
 
template<typename Handler >
Appput (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler)
 
template<typename Handler >
Apppatch (const std::string &path, Handler &&handler)
 
template<typename Handler >
Apppatch (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler)
 
template<typename Handler >
Appdel (const std::string &path, Handler &&handler)
 
template<typename Handler >
Appdel (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler)
 
template<typename Handler >
Appoptions (const std::string &path, Handler &&handler)
 
template<typename Handler >
Appoptions (const std::string &path, std::vector< routing::Middleware > mws, Handler &&handler)
 
Appws (const std::string &path, routing::WsHandler handler)
 Registers a WebSocket route.
 
concurrency::ThreadPoolget_thread_pool ()
 Retrieves the application's thread pool.
 
Appenable_metrics (const std::string &path="/metrics")
 Enables Prometheus metrics endpoint.
 
Appenable_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.
 

Detailed Description

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.

Examples
/home/runner/work/orbit-framework/orbit-framework/include/orbit/websocket/EventRouter.hpp.

Constructor & Destructor Documentation

◆ App() [1/2]

server::App::App ( const config::ServerConfig config)

Constructs a new App instance.

Parameters
configThe server configuration containing port, worker threads, and event engine preferences.

◆ ~App()

server::App::~App ( )

◆ App() [2/2]

server::App::App ( const App )
delete

Member Function Documentation

◆ del() [1/4]

template<typename Handler >
App & server::App::del ( const std::string &  path,
Handler &&  handler 
)
inline

◆ del() [2/4]

App & server::App::del ( const std::string &  path,
routing::RouteHandler  handler 
)

Registers a DELETE route.

Parameters
pathThe URL path.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ del() [3/4]

template<typename Handler >
App & server::App::del ( const std::string &  path,
std::vector< routing::Middleware mws,
Handler &&  handler 
)
inline

◆ del() [4/4]

App & server::App::del ( const std::string &  path,
std::vector< routing::Middleware mws,
routing::RouteHandler  handler 
)

Registers a DELETE route with middleware.

Parameters
pathThe URL path.
mwsA vector of middlewares to apply.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ enable_metrics()

App & server::App::enable_metrics ( const std::string &  path = "/metrics")

Enables Prometheus metrics endpoint.

Parameters
pathThe URL path for metrics (default is "/metrics").
Returns
Reference to the App instance for chaining.

◆ enable_openapi()

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.

Parameters
titleThe API title.
versionThe API version.
docs_pathThe URL path for Swagger UI.
json_pathThe URL path for the OpenAPI JSON.
Returns
Reference to the App instance for chaining.

◆ get() [1/4]

template<typename Handler >
App & server::App::get ( const std::string &  path,
Handler &&  handler 
)
inline

◆ get() [2/4]

App & server::App::get ( const std::string &  path,
routing::RouteHandler  handler 
)

Registers a GET route.

Parameters
pathThe URL path.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ get() [3/4]

template<typename Handler >
App & server::App::get ( const std::string &  path,
std::vector< routing::Middleware mws,
Handler &&  handler 
)
inline

◆ get() [4/4]

App & server::App::get ( const std::string &  path,
std::vector< routing::Middleware mws,
routing::RouteHandler  handler 
)

Registers a GET route with middleware.

Parameters
pathThe URL path.
mwsA vector of middlewares to apply.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ get_thread_pool()

concurrency::ThreadPool & server::App::get_thread_pool ( )
inline

Retrieves the application's thread pool.

Returns
Reference to the ThreadPool.
Exceptions
std::runtime_errorIf the server is not started.

◆ group()

App & server::App::group ( const std::string &  prefix,
std::function< void(routing::Router &)>  callback 
)
inline

Creates a route group with a specific prefix.

Parameters
prefixThe URL prefix for the group.
callbackA function to configure routes within the group.
Returns
Reference to the App instance for chaining.

◆ hot_reload()

void server::App::hot_reload ( )

Triggers a hot reload of the server configuration and routes.

◆ listen()

void server::App::listen ( )

Starts the server and blocks the current thread.

◆ on_error()

void server::App::on_error ( routing::ErrorHandler  handler)

Registers a global error handler for the application.

Parameters
handlerThe error handler function.

◆ operator=()

App & server::App::operator= ( const App )
delete

◆ options() [1/4]

template<typename Handler >
App & server::App::options ( const std::string &  path,
Handler &&  handler 
)
inline

◆ options() [2/4]

App & server::App::options ( const std::string &  path,
routing::RouteHandler  handler 
)

Registers an OPTIONS route.

Parameters
pathThe URL path.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ options() [3/4]

template<typename Handler >
App & server::App::options ( const std::string &  path,
std::vector< routing::Middleware mws,
Handler &&  handler 
)
inline

◆ options() [4/4]

App & server::App::options ( const std::string &  path,
std::vector< routing::Middleware mws,
routing::RouteHandler  handler 
)

Registers an OPTIONS route with middleware.

Parameters
pathThe URL path.
mwsA vector of middlewares to apply.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ patch() [1/4]

template<typename Handler >
App & server::App::patch ( const std::string &  path,
Handler &&  handler 
)
inline

◆ patch() [2/4]

App & server::App::patch ( const std::string &  path,
routing::RouteHandler  handler 
)

Registers a PATCH route.

Parameters
pathThe URL path.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ patch() [3/4]

template<typename Handler >
App & server::App::patch ( const std::string &  path,
std::vector< routing::Middleware mws,
Handler &&  handler 
)
inline

◆ patch() [4/4]

App & server::App::patch ( const std::string &  path,
std::vector< routing::Middleware mws,
routing::RouteHandler  handler 
)

Registers a PATCH route with middleware.

Parameters
pathThe URL path.
mwsA vector of middlewares to apply.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ post() [1/4]

template<typename Handler >
App & server::App::post ( const std::string &  path,
Handler &&  handler 
)
inline

◆ post() [2/4]

App & server::App::post ( const std::string &  path,
routing::RouteHandler  handler 
)

Registers a POST route.

Parameters
pathThe URL path.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ post() [3/4]

template<typename Handler >
App & server::App::post ( const std::string &  path,
std::vector< routing::Middleware mws,
Handler &&  handler 
)
inline

◆ post() [4/4]

App & server::App::post ( const std::string &  path,
std::vector< routing::Middleware mws,
routing::RouteHandler  handler 
)

Registers a POST route with middleware.

Parameters
pathThe URL path.
mwsA vector of middlewares to apply.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ put() [1/4]

template<typename Handler >
App & server::App::put ( const std::string &  path,
Handler &&  handler 
)
inline

◆ put() [2/4]

App & server::App::put ( const std::string &  path,
routing::RouteHandler  handler 
)

Registers a PUT route.

Parameters
pathThe URL path.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ put() [3/4]

template<typename Handler >
App & server::App::put ( const std::string &  path,
std::vector< routing::Middleware mws,
Handler &&  handler 
)
inline

◆ put() [4/4]

App & server::App::put ( const std::string &  path,
std::vector< routing::Middleware mws,
routing::RouteHandler  handler 
)

Registers a PUT route with middleware.

Parameters
pathThe URL path.
mwsA vector of middlewares to apply.
handlerThe route handler function.
Returns
Reference to the App instance for chaining.

◆ route()

routing::Router::RouteBuilder server::App::route ( const std::string &  path,
http::HttpMethod  method = http::HttpMethod::GET 
)
inline

Initiates a route builder for a specific path and method.

Parameters
pathThe URL path.
methodThe HTTP method (default is GET).
Returns
A RouteBuilder instance to configure the route.

◆ stop()

void server::App::stop ( )

Gracefully stops the server.

◆ use()

App & server::App::use ( routing::Middleware  m)

Registers a global middleware.

Parameters
mThe middleware function.
Returns
Reference to the App instance for chaining.

◆ ws()

App & server::App::ws ( const std::string &  path,
routing::WsHandler  handler 
)
inline

Registers a WebSocket route.

Parameters
pathThe URL path.
handlerThe WebSocket handler function.
Returns
Reference to the App instance for chaining.
Examples
/home/runner/work/orbit-framework/orbit-framework/include/orbit/websocket/EventRouter.hpp.

The documentation for this class was generated from the following file: