RESTinio
Loading...
Searching...
No Matches
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
using actual_request_handler_t
using non_matched_handler_t

Public Member Functions

 generic_express_router_t ()=default
 generic_express_router_t (generic_express_router_t &&)=default
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.
template<typename Method_Matcher>
void add_handler (Method_Matcher &&method_matcher, string_view_t route_path, actual_request_handler_t handler)
 Add handlers.
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

Private Attributes

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

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/extra_data_factory/main.cpp.

Definition at line 614 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
Initial value:
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.

Definition at line 617 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
Initial value:
Regex_Engine,
Extra_Data_Factory
A single generic express route entry.
Definition express.hpp:476
typename generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >::actual_request_handler_t actual_request_handler_t
Definition express.hpp:619

Definition at line 619 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
Initial value:
typename Extra_Data_Factory::data_t
>
std::function< request_handling_status_t(generic_request_handle_t< Extra_Data >) > generic_non_matched_request_handler_t
A generic type of handler for non-matched requests.

Definition at line 624 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
private
Initial value:
Regex_Engine,
Extra_Data_Factory
>

Definition at line 818 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 662 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 676 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 690 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 701 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 714 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 725 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 738 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 749 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 762 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 773 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 786 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 797 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 812 of file express.hpp.

◆ operator()()

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

Definition at line 634 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 824 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 827 of file express.hpp.


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