RESTinio
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory > Class Template Reference

Generic Express.js style router. More...

#include <express.hpp>

Public Types

using actual_request_handle_t = generic_request_handle_t< typename Extra_Data_Factory::data_t >
 
using actual_request_handler_t = typename generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >::actual_request_handler_t
 
using non_matched_handler_t = generic_non_matched_request_handler_t< typename Extra_Data_Factory::data_t >
 

Public Member Functions

 generic_express_router_t ()=default
 
 generic_express_router_t (generic_express_router_t &&)=default
 
RESTINIO_NODISCARD request_handling_status_t operator() (actual_request_handle_t req) const
 
void non_matched_request_handler (non_matched_handler_t nmrh)
 Set handler for requests that don't match any route. More...
 
template<typename Method_Matcher >
void add_handler (Method_Matcher &&method_matcher, string_view_t route_path, actual_request_handler_t handler)
 Add handlers. More...
 
template<typename Method_Matcher >
void add_handler (Method_Matcher &&method_matcher, string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
 
void http_delete (string_view_t route_path, actual_request_handler_t handler)
 
void http_delete (string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
 
void http_get (string_view_t route_path, actual_request_handler_t handler)
 
void http_get (string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
 
void http_head (string_view_t route_path, actual_request_handler_t handler)
 
void http_head (string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
 
void http_post (string_view_t route_path, actual_request_handler_t handler)
 
void http_post (string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
 
void http_put (string_view_t route_path, actual_request_handler_t handler)
 
void http_put (string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
 

Private Types

using route_entry_t = generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >
 

Private Attributes

std::vector< route_entry_tm_handlers
 A list of existing routes. More...
 
non_matched_handler_t m_non_matched_request_handler
 Handler that is called for requests that don't match any route. More...
 

Detailed Description

template<typename Regex_Engine, typename Extra_Data_Factory>
class restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >

Generic Express.js style router.

Express routers acts as a request handler (it means it is a function-object that can be called as a restinio request handler). It aggregates several endpoint-handlers and picks one or none of them to handle the request. The choice of the handler to execute depends on request target and HTTP method.

If router finds no handler matching the request then request is considered unmatched.

It is possible to set a handler for unmatched requests, otherwise router rejects the request and RESTinio takes care of it.

There is a difference between ordinary restinio request handler and the one that is used with experss router: generic_express_request_handler_t. The signature of a handlers that can be put in router has an additional parameter – a container with parameters extracted from URI (request target).

Template Parameters
Regex_EngineType of regex-engine to be used.
Extra_Data_FactoryType of extra-data-factory specified in server's traits.
Examples
sample/chained_handlers/main.cpp, sample/extra_data_factory/main.cpp, sample/file_upload/main.cpp, sample/hello_world/main.cpp, and sample/websocket_wss/main.cpp.

Definition at line 611 of file express.hpp.

Member Typedef Documentation

◆ actual_request_handle_t

template<typename Regex_Engine , typename Extra_Data_Factory >
using restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::actual_request_handle_t = generic_request_handle_t< typename Extra_Data_Factory::data_t >

Definition at line 614 of file express.hpp.

◆ actual_request_handler_t

template<typename Regex_Engine , typename Extra_Data_Factory >
using restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::actual_request_handler_t = typename generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >::actual_request_handler_t

Definition at line 616 of file express.hpp.

◆ non_matched_handler_t

template<typename Regex_Engine , typename Extra_Data_Factory >
using restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::non_matched_handler_t = generic_non_matched_request_handler_t< typename Extra_Data_Factory::data_t >

Definition at line 621 of file express.hpp.

◆ route_entry_t

template<typename Regex_Engine , typename Extra_Data_Factory >
using restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::route_entry_t = generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >
private

Definition at line 815 of file express.hpp.

Constructor & Destructor Documentation

◆ generic_express_router_t() [1/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::generic_express_router_t ( )
default

◆ generic_express_router_t() [2/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::generic_express_router_t ( generic_express_router_t< Regex_Engine, Extra_Data_Factory > &&  )
default

Member Function Documentation

◆ add_handler() [1/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
template<typename Method_Matcher >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::add_handler ( Method_Matcher &&  method_matcher,
string_view_t  route_path,
actual_request_handler_t  handler 
)
inline

Add handlers.

Definition at line 659 of file express.hpp.

◆ add_handler() [2/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
template<typename Method_Matcher >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::add_handler ( Method_Matcher &&  method_matcher,
string_view_t  route_path,
const path2regex::options_t options,
actual_request_handler_t  handler 
)
inline

Definition at line 673 of file express.hpp.

◆ http_delete() [1/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_delete ( string_view_t  route_path,
actual_request_handler_t  handler 
)
inline

Definition at line 687 of file express.hpp.

◆ http_delete() [2/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_delete ( string_view_t  route_path,
const path2regex::options_t options,
actual_request_handler_t  handler 
)
inline

Definition at line 698 of file express.hpp.

◆ http_get() [1/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_get ( string_view_t  route_path,
actual_request_handler_t  handler 
)
inline

Definition at line 711 of file express.hpp.

◆ http_get() [2/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_get ( string_view_t  route_path,
const path2regex::options_t options,
actual_request_handler_t  handler 
)
inline

Definition at line 722 of file express.hpp.

◆ http_head() [1/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_head ( string_view_t  route_path,
actual_request_handler_t  handler 
)
inline

Definition at line 735 of file express.hpp.

◆ http_head() [2/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_head ( string_view_t  route_path,
const path2regex::options_t options,
actual_request_handler_t  handler 
)
inline

Definition at line 746 of file express.hpp.

◆ http_post() [1/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_post ( string_view_t  route_path,
actual_request_handler_t  handler 
)
inline

Definition at line 759 of file express.hpp.

◆ http_post() [2/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_post ( string_view_t  route_path,
const path2regex::options_t options,
actual_request_handler_t  handler 
)
inline

Definition at line 770 of file express.hpp.

◆ http_put() [1/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_put ( string_view_t  route_path,
actual_request_handler_t  handler 
)
inline

Definition at line 783 of file express.hpp.

◆ http_put() [2/2]

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::http_put ( string_view_t  route_path,
const path2regex::options_t options,
actual_request_handler_t  handler 
)
inline

Definition at line 794 of file express.hpp.

◆ non_matched_request_handler()

template<typename Regex_Engine , typename Extra_Data_Factory >
void restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::non_matched_request_handler ( non_matched_handler_t  nmrh)
inline

Set handler for requests that don't match any route.

Definition at line 809 of file express.hpp.

◆ operator()()

template<typename Regex_Engine , typename Extra_Data_Factory >
RESTINIO_NODISCARD request_handling_status_t restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::operator() ( actual_request_handle_t  req) const
inline

Definition at line 631 of file express.hpp.

Member Data Documentation

◆ m_handlers

template<typename Regex_Engine , typename Extra_Data_Factory >
std::vector< route_entry_t > restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::m_handlers
private

A list of existing routes.

Definition at line 821 of file express.hpp.

◆ m_non_matched_request_handler

template<typename Regex_Engine , typename Extra_Data_Factory >
non_matched_handler_t restinio::router::generic_express_router_t< Regex_Engine, Extra_Data_Factory >::m_non_matched_request_handler
private

Handler that is called for requests that don't match any route.

Definition at line 824 of file express.hpp.


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