61 std::vector< std::pair< string_view_t, string_view_t > >;
63 std::vector< string_view_t >;
70 std::unique_ptr<
char[] > request_target,
71 std::shared_ptr< std::string > key_names_buffer,
126 throw exception_t{ fmt::format(
"invalid parameter index: {}", i ) };
138 named_parameters_container_t::const_iterator
146 return key == p.first;
150 named_parameters_container_t::const_reference
158 "invalid parameter name: {}",
159 std::string{ key.data(), key.size() } ) };
205 std::unique_ptr<
char[] > request_target,
206 std::shared_ptr< std::string > key_names_buffer,
224 return rp.m_named_parameters;
230 return rp.m_indexed_parameters;
280template <
typename Regex_Engine = std_regex_engine_t >
284 using regex_t =
typename Regex_Engine::compiled_regex_t;
291 std::shared_ptr< std::string > named_params_buffer,
308 template<
typename Method_Matcher >
310 Method_Matcher && method_matcher,
312 std::shared_ptr< std::string > named_params_buffer,
320 std::forward<Method_Matcher>(method_matcher) );
333 if( Regex_Engine::try_match(
345 captured_params.get() + Regex_Engine::submatch_begin_pos( matches[0] ),
346 Regex_Engine::submatch_end_pos( matches[0] ) -
347 Regex_Engine::submatch_begin_pos( matches[0] ) } ;
360 for( ; i < matches.size(); ++i )
362 const auto & m = matches[ i ];
366 captured_params.get() + Regex_Engine::submatch_begin_pos( m ),
367 Regex_Engine::submatch_end_pos( m ) -
368 Regex_Engine::submatch_begin_pos( m ) } );
438template<
typename Extra_Data >
470 typename Regex_Engine,
471 typename Extra_Data_Factory >
476 typename Extra_Data_Factory::data_t
479 typename Extra_Data_Factory::data_t
488 template<
typename Method_Matcher >
490 Method_Matcher && method_matcher,
494 std::forward<Method_Matcher>( method_matcher ),
495 std::
move( matcher_data.m_regex ),
496 std::
move( matcher_data.m_named_params_buffer ),
497 std::
move( matcher_data.m_param_appender_sequence ) }
514 template<
typename Method_Matcher >
516 Method_Matcher && method_matcher,
521 std::forward<Method_Matcher>( method_matcher ),
528 template<
typename Method_Matcher >
530 Method_Matcher && method_matcher,
534 std::forward<Method_Matcher>( method_matcher ),
549 return m_matcher( h, target_path, params );
609 typename Regex_Engine,
610 typename Extra_Data_Factory >
623 typename Extra_Data_Factory::data_t
637 if( entry.match( req->header(), target_path, params ) )
657 template<
typename Method_Matcher >
660 Method_Matcher && method_matcher,
665 std::forward<Method_Matcher>(method_matcher),
671 template<
typename Method_Matcher >
674 Method_Matcher && method_matcher,
680 std::forward<Method_Matcher>(method_matcher),
692 http_method_delete(),
704 http_method_delete(),
848template <
typename Value_Type >
852 return get< Value_Type >( params[ key ] );
856template <
typename Value_Type >
860 return 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.
RESTINIO_NODISCARD 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, 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
RESTINIO_NODISCARD 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(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
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
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_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)
void http_put(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
generic_non_matched_request_handler_t< typename Extra_Data_Factory::data_t > non_matched_handler_t
void non_matched_request_handler(non_matched_handler_t nmrh)
Set handler for requests that don't match any route.
RESTINIO_NODISCARD request_handling_status_t operator()(actual_request_handle_t req) const
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
void http_delete(string_view_t route_path, const path2regex::options_t &options, actual_request_handler_t handler)
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
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)
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
typename generic_express_route_entry_t< Regex_Engine, Extra_Data_Factory >::actual_request_handler_t actual_request_handler_t
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.
RESTINIO_NODISCARD string_view_t view() const noexcept
Get access to the value of target_path.
RESTINIO_NODISCARD data_t giveout_data() noexcept
Give out the value from holder.
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
optional_t< string_view_t > get_param(string_view_t key) const noexcept
Get the value of a parameter if it exists.
bool has(string_view_t key) const noexcept
Check parameter.
std::vector< string_view_t > indexed_parameters_container_t
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.
std::vector< std::pair< string_view_t, string_view_t > > named_parameters_container_t
string_view_t match() const noexcept
Matched route.
named_parameters_container_t m_named_parameters
Named params.
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.
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_NODISCARD
Stuff related to method_matchers.
const nullopt_t nullopt((nullopt_t::init()))
auto path2regex(string_view_t path, const options_t &options)
The main path matching regexp.
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.
RESTINIO_NODISCARD constexpr request_handling_status_t request_not_handled() noexcept
nonstd::string_view string_view_t
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
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 RESTINIO_NODISCARD 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.