RESTinio
Loading...
Searching...
No Matches
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
 
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/async_chained_handlers/main.cpp, 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 614 of file express.hpp.

Member Typedef Documentation

◆ actual_request_handle_t

Initial value:
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.

Definition at line 617 of file express.hpp.

◆ actual_request_handler_t

Initial value:
typename generic_express_route_entry_t<
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

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

Initial value:
generic_express_route_entry_t<
>

Definition at line 818 of file express.hpp.

Constructor & Destructor Documentation

◆ generic_express_router_t() [1/2]

◆ generic_express_router_t() [2/2]

Member Function Documentation

◆ add_handler() [1/2]

Add handlers.

Definition at line 662 of file express.hpp.

◆ add_handler() [2/2]

Definition at line 676 of file express.hpp.

◆ http_delete() [1/2]

Definition at line 690 of file express.hpp.

◆ http_delete() [2/2]

Definition at line 701 of file express.hpp.

◆ http_get() [1/2]

Definition at line 714 of file express.hpp.

◆ http_get() [2/2]

Definition at line 725 of file express.hpp.

◆ http_head() [1/2]

Definition at line 738 of file express.hpp.

◆ http_head() [2/2]

Definition at line 749 of file express.hpp.

◆ http_post() [1/2]

Definition at line 762 of file express.hpp.

◆ http_post() [2/2]

Definition at line 773 of file express.hpp.

◆ http_put() [1/2]

Definition at line 786 of file express.hpp.

◆ http_put() [2/2]

Definition at line 797 of file express.hpp.

◆ non_matched_request_handler()

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

Definition at line 812 of file express.hpp.

◆ operator()()

Definition at line 634 of file express.hpp.

Member Data Documentation

◆ m_handlers

A list of existing routes.

Definition at line 824 of file express.hpp.

◆ m_non_matched_request_handler

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: