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 = 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.
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 = generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >

## Private Attributes

std::vector< route_entry_t > | m_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_Engine | Type of regex-engine to be used.
  Extra_Data_Factory | Type 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 615 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 618 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 620 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 625 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 819 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 663 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 677 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 691 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 702 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 715 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 726 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 739 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 750 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 763 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 774 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 787 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 798 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 813 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 635 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 825 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 828 of file express.hpp.

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

- restinio/router/express.hpp