ゴミ箱
Classes | Public Types | Public Member Functions | List of all members
http::Router Class Reference

#include <router.hpp>

Classes

struct  Context
 
class  Route
 

Public Types

typedef std::unordered_map< std::string, std::string > matches
 
typedef std::function< void(Context &&)> router_handler
 Type of route's handler. More...
 

Public Member Functions

 Router () noexcept
 Initializes router. More...
 
Routeradd_route (Method method, const char *route, router_handler fn)
 
bool dispatch (const boost::asio::ip::tcp::socket &socket, const dynamic_request &request, dynamic_response &response) const noexcept
 
bool is_method_used (boost::beast::http::verb method) const noexcept
 

Detailed Description

HTTP Router class

Member Typedef Documentation

typedef std::unordered_map<std::string, std::string> http::Router::matches
typedef std::function<void(Context&&)> http::Router::router_handler

Type of route's handler.

Constructor & Destructor Documentation

Router::Router ( )
noexcept

Initializes router.

Member Function Documentation

Router & Router::add_route ( Method  method,
const char *  route,
router_handler  fn 
)

Adds route's handler.

Parameters
methodRouter's method.
routeString with URI path relative to host <host:port></route>
fnHandler for route.
Note
Routes can be overridden.
bool Router::dispatch ( const boost::asio::ip::tcp::socket &  socket,
const dynamic_request request,
dynamic_response response 
) const
noexcept

Dispatches Beast HTTP request.

Parameters
socketBoost asio's socket.
requestBeast HTTP request.
responseBeast HTTP response.
Return values
trueIf corresponding handler is found.
falseOtherwise.
bool Router::is_method_used ( boost::beast::http::verb  method) const
noexcept
Returns
Whether method is used by Router.

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