60 std::vector< std::pair< string_view_t, string_view_t > >;
62 std::vector< string_view_t >;
69 std::unique_ptr<
char[] > request_target,
110 std::optional< string_view_t >
116 std::optional< string_view_t >{
it->second } :
117 std::optional< string_view_t >{ std::nullopt };
141 named_parameters_container_t::const_iterator
149 return key == p.first;
153 named_parameters_container_t::const_reference
162 std::string{
key.data(),
key.size() } ) };
208 std::unique_ptr<
char[] > request_target,
215 std::move( request_target ),
227 return rp.m_named_parameters;
233 return rp.m_indexed_parameters;
283template <
typename Regex_Engine = std_regex_engine_t >
287 using regex_t =
typename Regex_Engine::compiled_regex_t;
311 template<
typename Method_Matcher >
336 if( Regex_Engine::try_match(
349 Regex_Engine::submatch_end_pos(
matches[0] ) -
350 Regex_Engine::submatch_begin_pos(
matches[0] ) } ;
370 Regex_Engine::submatch_end_pos(
m ) -
371 Regex_Engine::submatch_begin_pos(
m ) } );
387 std::move( named_parameters ),
388 std::move( indexed_parameters ) );
441template<
typename Extra_Data >
479 typename Extra_Data_Factory::data_t
482 typename Extra_Data_Factory::data_t
491 template<
typename Method_Matcher >
517 template<
typename Method_Matcher >
525 path2regex::path2regex< impl::route_params_appender_t,
Regex_Engine >(
531 template<
typename Method_Matcher >
539 path2regex::options_t{},
626 typename Extra_Data_Factory::data_t
642 return entry.handle( std::move(
req ), std::move( params ) );
660 template<
typename Method_Matcher >
674 template<
typename Method_Matcher >
851template <
typename Value_Type >
855 return std::get< Value_Type >( params[
key ] );
859template <
typename Value_Type >
863 return std::get< Value_Type >( params[ index ] );
Exception class for all exceptions thrown by RESTinio.
A type for representation of HTTP method ID.
Options for matching routes.
A single generic express route entry.
generic_express_route_entry_t(Method_Matcher &&method_matcher, matcher_init_data_t matcher_data, actual_request_handler_t handler)
generic_express_request_handler_t< typename Extra_Data_Factory::data_t > actual_request_handler_t
generic_express_route_entry_t & operator=(const generic_express_route_entry_t &)=delete
generic_express_route_entry_t(Method_Matcher &&method_matcher, string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
generic_express_route_entry_t(generic_express_route_entry_t &&)=default
bool match(const http_request_header_t &h, impl::target_path_holder_t &target_path, route_params_t ¶ms) const
Checks if request header matches entry, and if so, set route params.
generic_express_route_entry_t(Method_Matcher &&method_matcher, string_view_t route_path, actual_request_handler_t handler)
generic_express_route_entry_t & operator=(generic_express_route_entry_t &&)=default
actual_request_handler_t m_handler
generic_express_route_entry_t()=default
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
request_handling_status_t handle(actual_request_handle_t rh, route_params_t rp) const
Calls a handler of given request with given params.
generic_express_route_entry_t(const generic_express_route_entry_t &)=delete
impl::route_matcher_t< Regex_Engine > m_matcher
Generic Express.js style router.
void http_post(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)
request_handling_status_t operator()(actual_request_handle_t req) const
void http_put(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
void non_matched_request_handler(non_matched_handler_t nmrh)
Set handler for requests that don't match any route.
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
non_matched_handler_t m_non_matched_request_handler
Handler that is called for requests that don't match any route.
void http_head(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
generic_express_router_t()=default
typename generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >::actual_request_handler_t actual_request_handler_t
void http_delete(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)
std::vector< route_entry_t > m_handlers
A list of existing routes.
void add_handler(Method_Matcher &&method_matcher, 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_head(string_view_t route_path, actual_request_handler_t handler)
void http_post(string_view_t route_path, actual_request_handler_t handler)
generic_non_matched_request_handler_t< typename Extra_Data_Factory::data_t > non_matched_handler_t
void http_get(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
void add_handler(Method_Matcher &&method_matcher, string_view_t route_path, actual_request_handler_t handler)
Add handlers.
generic_express_router_t(generic_express_router_t &&)=default
A special class that allows to hold a copy of small-size method_matchers or a pointer to dynamically ...
A matcher for a given path.
route_matcher_t(Method_Matcher &&method_matcher, regex_t route_regex, std::shared_ptr< std::string > named_params_buffer, param_appender_sequence_t param_appender_sequence)
buffered_matcher_holder_t m_method_matcher
HTTP method to match.
regex_t m_route_regex
Regex of a given route.
param_appender_sequence_t m_param_appender_sequence
Parameters values.
bool match_route(target_path_holder_t &target_path, route_params_t ¶meters) const
Try to match a given request target with this route.
typename Regex_Engine::match_results_t match_results_t
bool operator()(const http_request_header_t &h, target_path_holder_t &target_path, route_params_t ¶meters) const
route_matcher_t()=default
std::shared_ptr< std::string > m_named_params_buffer
Buffer for named parameters names string views.
typename Regex_Engine::compiled_regex_t regex_t
route_matcher_t(route_matcher_t &&)=default
route_matcher_t(http_method_id_t method, regex_t route_regex, std::shared_ptr< std::string > named_params_buffer, param_appender_sequence_t param_appender_sequence)
Creates matcher with a given parameters.
Helper class for gthering parameters from route.
route_params_t::indexed_parameters_container_t & m_indexed_parameters
void add_indexed_param(string_view_t value)
void add_named_param(string_view_t key, string_view_t value)
route_params_t::named_parameters_container_t & m_named_parameters
route_params_appender_t(route_params_appender_t &&)=delete
route_params_appender_t & operator=(const route_params_appender_t &)=delete
route_params_appender_t(const route_params_appender_t &)=delete
route_params_appender_t(route_params_t::named_parameters_container_t &named_parameters, route_params_t::indexed_parameters_container_t &indexed_parameters)
Helper class for holding a unique instance of char array with target_path value.
Parameters extracted from route.
named_parameters_container_t::const_reference find_named_parameter_with_check(string_view_t key) const
auto indexed_parameters_size() const noexcept
bool has(string_view_t key) const noexcept
Check parameter.
void match(std::unique_ptr< char[] > request_target, std::shared_ptr< std::string > key_names_buffer, string_view_t match, named_parameters_container_t named_parameters, indexed_parameters_container_t indexed_parameters)
route_params_t(const route_params_t &)=delete
std::unique_ptr< char[] > m_request_target
A raw request target.
string_view_t match() const noexcept
Matched route.
named_parameters_container_t m_named_parameters
Named params.
std::vector< string_view_t > indexed_parameters_container_t
route_params_t & operator=(route_params_t &&)=default
auto named_parameters_size() const noexcept
Get number of parameters.
indexed_parameters_container_t m_indexed_parameters
Indexed params.
route_params_t(route_params_t &&)=default
string_view_t operator[](string_view_t key) const
Get named parameter.
std::optional< string_view_t > get_param(string_view_t key) const noexcept
Get the value of a parameter if it exists.
std::vector< std::pair< string_view_t, string_view_t > > named_parameters_container_t
named_parameters_container_t::const_iterator find_named_parameter(string_view_t key) const noexcept
string_view_t m_match
Matched pattern.
std::shared_ptr< std::string > m_key_names_buffer
Shared buffer for string_view of named parameterts names.
#define RESTINIO_FMT_FORMAT_STRING(s)
Stuff related to method_matchers.
std::vector< param_appender_t< Route_Param_Appender > > param_appender_sequence_t
A sequence of appenders for submatches.
path2regex::param_appender_sequence_t< route_params_appender_t > param_appender_sequence_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.
std::function< request_handling_status_t( generic_request_handle_t< Extra_Data >, route_params_t) > generic_express_request_handler_t
Type of generic handler for one route.
generic_express_request_handler_t< no_extra_data_factory_t::data_t > express_request_handler_t
Type of a handler for one route in the case when there is no extra-data in request object.
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
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.
std::string_view string_view_t
constexpr request_handling_status_t request_not_handled() noexcept
request_handling_status_t
Request handling status.
Value_Type get(const router::route_params_t ¶ms, string_view_t key)
Cast named parameter value to a given type.
The definition of the non_matched_request_handler type.
Resulting regex and param extraction for a specific route.
Route params private internals accessor.
static const auto & named_parameters(const route_params_t &rp) noexcept
Get values containers for all parameters (used in unit tests).
static const auto & indexed_parameters(const route_params_t &rp) noexcept
static void match(route_params_t &rp, std::unique_ptr< char[] > request_target, std::shared_ptr< std::string > key_names_buffer, string_view_t match_, route_params_t::named_parameters_container_t named_parameters, route_params_t::indexed_parameters_container_t indexed_parameters)
Init parameters with a matched route params.
virtual bool match(const http_method_id_t &method) const noexcept=0
Is the specified method can be applied to a route?
Regex engine implementation for using with standard regex implementation.
Implementation of target_path_holder helper class.