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

Manages routing of HTTP requests to their appropriate handlers. More...

#include <Router.hpp>

Classes

class  RouteBuilder
 A builder class for fluent route configuration. More...
 

Public Member Functions

 Router (const std::string &prefix="", Router *parent=nullptr)
 Constructs a new Router.
 
RouteBuilder route (const std::string &path, http::HttpMethod method=http::HttpMethod::GET)
 Initiates a route builder for a specific path and method.
 
void group (const std::string &prefix, std::function< void(Router &)> callback)
 Creates a route group with a specific prefix.
 
void add_route (http::HttpMethod method, const std::string &path, RouteHandler handler)
 
void add_route (http::HttpMethod method, const std::string &path, std::vector< Middleware > mws, RouteHandler handler)
 
void add_route_with_meta (http::HttpMethod method, const std::string &path, std::vector< Middleware > mws, const openapi::RouteMetadata &meta, RouteHandler handler)
 
Routerget (const std::string &path, RouteHandler handler)
 
Routerget (const std::string &path, std::vector< Middleware > mws, RouteHandler handler)
 
Routerpost (const std::string &path, RouteHandler handler)
 
Routerpost (const std::string &path, std::vector< Middleware > mws, RouteHandler handler)
 
Routerput (const std::string &path, RouteHandler handler)
 
Routerput (const std::string &path, std::vector< Middleware > mws, RouteHandler handler)
 
Routerpatch (const std::string &path, RouteHandler handler)
 
Routerpatch (const std::string &path, std::vector< Middleware > mws, RouteHandler handler)
 
Routerdel (const std::string &path, RouteHandler handler)
 
Routerdel (const std::string &path, std::vector< Middleware > mws, RouteHandler handler)
 
Routeroptions (const std::string &path, RouteHandler handler)
 
Routeroptions (const std::string &path, std::vector< Middleware > mws, RouteHandler handler)
 
void ws (const std::string &path, WsHandler handler)
 
void use (Middleware m)
 
void on_error (ErrorHandler handler)
 
void route (http::HttpRequest &request, std::shared_ptr< http::ResponseWriter > response_writer) const
 
bool has_ws_route (const std::string &path) const
 
WsHandler get_ws_route (const std::string &path) const
 
bool is_stream_route (http::HttpMethod method, const std::string &path) const
 
void add_stream_route (http::HttpMethod method, const std::string &path, RouteHandler handler)
 

Detailed Description

Manages routing of HTTP requests to their appropriate handlers.

Constructor & Destructor Documentation

◆ Router()

routing::Router::Router ( const std::string &  prefix = "",
Router parent = nullptr 
)
inline

Constructs a new Router.

Parameters
prefixThe route prefix for this router.
parentPointer to the parent router, if any.

Member Function Documentation

◆ add_route() [1/2]

void routing::Router::add_route ( http::HttpMethod  method,
const std::string &  path,
RouteHandler  handler 
)

◆ add_route() [2/2]

void routing::Router::add_route ( http::HttpMethod  method,
const std::string &  path,
std::vector< Middleware mws,
RouteHandler  handler 
)

◆ add_route_with_meta()

void routing::Router::add_route_with_meta ( http::HttpMethod  method,
const std::string &  path,
std::vector< Middleware mws,
const openapi::RouteMetadata meta,
RouteHandler  handler 
)

◆ add_stream_route()

void routing::Router::add_stream_route ( http::HttpMethod  method,
const std::string &  path,
RouteHandler  handler 
)

◆ del() [1/2]

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

◆ del() [2/2]

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

◆ get() [1/2]

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

◆ get() [2/2]

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

◆ get_ws_route()

WsHandler routing::Router::get_ws_route ( const std::string &  path) const

◆ group()

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

Creates a route group with a specific prefix.

Parameters
prefixThe URL prefix for the group.
callbackA function to configure routes within the group.

◆ has_ws_route()

bool routing::Router::has_ws_route ( const std::string &  path) const

◆ is_stream_route()

bool routing::Router::is_stream_route ( http::HttpMethod  method,
const std::string &  path 
) const

◆ on_error()

void routing::Router::on_error ( ErrorHandler  handler)

◆ options() [1/2]

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

◆ options() [2/2]

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

◆ patch() [1/2]

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

◆ patch() [2/2]

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

◆ post() [1/2]

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

◆ post() [2/2]

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

◆ put() [1/2]

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

◆ put() [2/2]

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

◆ route() [1/2]

RouteBuilder routing::Router::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.
router.route("/users", HttpMethod::POST)
.summary("Create a user")
.handler([](auto& req, auto res) { ... });

◆ route() [2/2]

void routing::Router::route ( http::HttpRequest request,
std::shared_ptr< http::ResponseWriter response_writer 
) const

◆ use()

void routing::Router::use ( Middleware  m)

◆ ws()

void routing::Router::ws ( const std::string &  path,
WsHandler  handler 
)

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