Go to the documentation of this file.
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;
280 template <
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 ) } );
436 template <
typename Regex_Engine = std_regex_engine_t>
444 template<
typename Method_Matcher >
446 Method_Matcher && method_matcher,
450 std::forward<Method_Matcher>( method_matcher ),
466 template<
typename Method_Matcher >
468 Method_Matcher && method_matcher,
473 std::forward<Method_Matcher>( method_matcher ),
474 path2regex::path2regex< impl::route_params_appender_t, Regex_Engine >(
480 template<
typename Method_Matcher >
482 Method_Matcher && method_matcher,
486 std::forward<Method_Matcher>( method_matcher ),
501 return m_matcher( h, target_path, params );
536 template <
typename Regex_Engine = std_regex_engine_t>
551 if( entry.match( req->header(), target_path, params ) )
571 template<
typename Method_Matcher >
574 Method_Matcher && method_matcher,
579 std::forward<Method_Matcher>(method_matcher),
585 template<
typename Method_Matcher >
588 Method_Matcher && method_matcher,
594 std::forward<Method_Matcher>(method_matcher),
606 http_method_delete(),
618 http_method_delete(),
741 template <
typename Value_Type >
745 return get< Value_Type >( params[ key ] );
749 template <
typename Value_Type >
753 return get< Value_Type >( params[ index ] );
route_params_appender_t(const route_params_appender_t &)=delete
Exception class for all exceptions thrown by RESTinio.
RESTINIO_NODISCARD data_t giveout_data() noexcept
Give out the value from holder.
A type for representation of HTTP method ID.
route_params_t::indexed_parameters_container_t & m_indexed_parameters
#define RESTINIO_NODISCARD
named_parameters_container_t::const_reference find_named_parameter_with_check(string_view_t key) const
A special class that allows to hold a copy of small-size method_matchers or a pointer to dynamically ...
void http_put(string_view_t route_path, const path2regex::options_t &options, express_request_handler_t handler)
std::shared_ptr< std::string > m_key_names_buffer
Shared buffer for string_view of named parameterts names.
void http_head(string_view_t route_path, const path2regex::options_t &options, express_request_handler_t handler)
void http_delete(string_view_t route_path, express_request_handler_t handler)
auto indexed_parameters_size() const 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.
route_matcher_t()=default
route_params_t(const route_params_t &)=delete
void non_matched_request_handler(non_matched_request_handler_t nmrh)
Set handler for requests that don't match any route.
auto named_parameters_size() const noexcept
Get number of parameters.
std::vector< string_view_t > indexed_parameters_container_t
std::vector< param_appender_t< Route_Param_Appender > > param_appender_sequence_t
A sequence of appenders for submatches.
express_route_entry_t(const express_route_entry_t &)=delete
Options for matching routes.
void http_put(string_view_t route_path, express_request_handler_t handler)
nonstd::string_view string_view_t
express_router_t(express_router_t &&)=default
route_params_appender_t & operator=(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)
route_params_t & operator=(route_params_t &&)=default
express_route_entry_t & operator=(const express_route_entry_t &)=delete
std::function< request_handling_status_t(request_handle_t, route_params_t) > express_request_handler_t
Route params private internals accessor.
typename Regex_Engine::match_results_t match_results_t
std::shared_ptr< std::string > m_named_params_buffer
Buffer for named parameters names string views.
void add_handler(Method_Matcher &&method_matcher, string_view_t route_path, express_request_handler_t handler)
Add handlers.
string_view_t m_match
Matched pattern.
express_route_entry_t(Method_Matcher &&method_matcher, string_view_t route_path, const path2regex::options_t &options, express_request_handler_t handler)
std::shared_ptr< std::string > m_named_params_buffer
Char buffer for holding named paramaters.
virtual RESTINIO_NODISCARD bool match(const http_method_id_t &method) const noexcept=0
Is the specified method can be applied to a route?
A single express route entry.
express_route_entry_t(express_route_entry_t &&)=default
Implementation of target_path_holder helper class.
Helper class for holding a unique instance of char array with target_path value.
Resulting regex and param extraction for a specific route.
express_route_entry_t(Method_Matcher &&method_matcher, matcher_init_data_t matcher_data, express_request_handler_t handler)
express_route_entry_t(Method_Matcher &&method_matcher, string_view_t route_path, express_request_handler_t handler)
void http_post(string_view_t route_path, const path2regex::options_t &options, express_request_handler_t handler)
indexed_parameters_container_t m_indexed_parameters
Indexed params.
string_view_t match() const noexcept
Matched route.
void add_indexed_param(string_view_t value)
param_appender_sequence_t< Route_Param_Appender > m_param_appender_sequence
Appenders for captured values (names/indexed groups).
request_handling_status_t
Request handling status.
named_parameters_container_t::const_iterator find_named_parameter(string_view_t key) const noexcept
RESTINIO_NODISCARD request_handling_status_t operator()(request_handle_t req) const
bool operator()(const http_request_header_t &h, target_path_holder_t &target_path, route_params_t ¶meters) const
std::unique_ptr< char[] > m_request_target
A raw request target.
bool match_route(target_path_holder_t &target_path, route_params_t ¶meters) const
Try to match a given request target with this route.
route_params_t::named_parameters_container_t & m_named_parameters
static const auto & indexed_parameters(const route_params_t &rp) noexcept
route_matcher_t(route_matcher_t &&)=default
static const auto & named_parameters(const route_params_t &rp) noexcept
Get values containers for all parameters (used in unit tests).
regex_t m_route_regex
Regex of a given route.
impl::route_matcher_t< Regex_Engine > m_matcher
string_view_t operator[](string_view_t key) const
Get named parameter.
void http_head(string_view_t route_path, express_request_handler_t handler)
const nullopt_t nullopt((nullopt_t::init()))
std::function< request_handling_status_t(request_handle_t) > non_matched_request_handler_t
param_appender_sequence_t m_param_appender_sequence
Parameters values.
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.
RESTINIO_NODISCARD request_handling_status_t handle(request_handle_t rh, route_params_t rp) const
Calls a handler of given request with given params.
named_parameters_container_t m_named_parameters
Named params.
buffered_matcher_holder_t m_method_matcher
HTTP method to match.
typename Regex_Engine::compiled_regex_t regex_t
Stuff related to method_matchers.
Parameters extracted from route.
void http_get(string_view_t route_path, const path2regex::options_t &options, express_request_handler_t handler)
void add_named_param(string_view_t key, string_view_t value)
std::vector< route_entry_t > m_handlers
A list of existing routes.
path2regex::param_appender_sequence_t< route_params_appender_t > param_appender_sequence_t
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.
void add_handler(Method_Matcher &&method_matcher, string_view_t route_path, const path2regex::options_t &options, express_request_handler_t handler)
bool has(string_view_t key) const noexcept
Check parameter.
A matcher for a given path.
Helper class for gthering parameters from route.
non_matched_request_handler_t m_non_matched_request_handler
Handler that is called for requests that don't match any route.
std::vector< std::pair< string_view_t, string_view_t > > named_parameters_container_t
RESTINIO_NODISCARD string_view_t view() const noexcept
Get access to the value of target_path.
void http_get(string_view_t route_path, express_request_handler_t handler)
std::shared_ptr< request_t > request_handle_t
Request handler, that is the type for calling request handlers.
express_route_entry_t()=default
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(route_params_t &&)=default
void http_post(string_view_t route_path, express_request_handler_t handler)
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)
optional_t< string_view_t > get_param(string_view_t key) const noexcept
Get the value of a parameter if it exists.
Value_Type get(const router::route_params_t ¶ms, string_view_t key)
Cast named parameter value to a given type.
constexpr request_handling_status_t request_rejected() noexcept
route_params_appender_t(route_params_appender_t &&)=delete
express_request_handler_t m_handler
express_router_t()=default
The definition of the non_matched_request_handler type.
void http_delete(string_view_t route_path, const path2regex::options_t &options, express_request_handler_t handler)