28namespace easy_parser_router
54template<
typename Extra_Data >
85template<
typename Extra_Data >
87 std::unique_ptr< router_entry_t< Extra_Data > >;
105template<
typename Extra_Data,
typename Producer,
typename Handler >
122 typename Method_Matcher,
123 typename Producer_Arg,
124 typename Handler_Arg >
126 Method_Matcher && method_matcher,
127 Producer_Arg && producer,
128 Handler_Arg && handler )
148 return Producer::invoke_handler( req,
m_handler, *parse_result );
165template<
typename Unescape_Traits >
175 return restinio::utils::unescape_percent_encoding< Unescape_Traits >(
189template<
typename Producer, std::
size_t Index >
191 :
public ep::impl::consume_value_clause_t<
193 ep::impl::tuple_item_consumer_t<Index> >
202 template<
typename Producer_Arg >
207 return { std::forward<Producer_Arg>(producer) };
211 template<
typename Producer_Arg >
232template< std::
size_t Size >
234 :
public ep::impl::consume_value_clause_t<
235 ep::impl::exact_fixed_size_fragment_producer_t<Size>,
236 ep::impl::any_value_skipper_t >
238 using producer_t = ep::impl::exact_fixed_size_fragment_producer_t<Size>;
247 const char (&fragment)[Size] )
266 :
public ep::impl::consume_value_clause_t<
267 ep::impl::exact_fragment_producer_t,
268 ep::impl::any_value_skipper_t >
293template<
typename H,
typename R,
bool Is_Producer >
298 template<
class...>
class To,
299 typename... Results >
307 template<
class...>
class To,
308 typename... Results >
311 using type = To<Results...,
typename H::result_type>;
315template<
typename H,
typename R >
321template<
typename From,
typename To >
326 template<
class...>
class From,
328 template<
class...>
class To,
329 typename... Results >
336 To< Results... > >::type
341 template<
class...>
class From,
342 template<
class...>
class To,
343 typename... Results >
350template<
typename Args_Type_List >
360template<
typename Args_Type_List >
372template<
typename T,
bool Is_Producer, std::
size_t Current_Index >
379template< std::
size_t Size, std::
size_t Current_Index >
386template< std::
size_t Current_Index >
393template< std::
size_t Current_Index >
400template<
typename T, std::
size_t Current_Index >
404 static constexpr std::size_t
next_index = Current_Index + 1u;
411template<
typename From,
typename To, std::
size_t Current_Index >
415 template<
class...>
class From,
417 template<
class...>
class To,
419 std::size_t Current_Index >
427 ep::impl::is_producer_v<head_type>,
434 one_clause_type::next_index >::type;
438 template<
class...>
class From,
439 template<
class...>
class To,
441 std::size_t Current_Index >
449template<
typename Args_Type_List >
460template<
typename Args_Type_List >
480template<
typename T >
484 using U = std::remove_reference_t<T>;
487 using type =
typename std::conditional<
488 std::is_array<U>::value,
512template<
typename... Args >
515 static_assert( 0u !=
sizeof...(Args),
"Args can't be an empty list" );
537 typename Target_Type,
538 typename Subitems_Tuple >
540 :
public ep::impl::produce_t< Target_Type, Subitems_Tuple >
542 using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
545 using base_type_t::base_type_t;
547 template<
typename Extra_Data,
typename Handler >
553 typename base_type_t::result_type & type )
555 return handler( req, type );
559namespace path_to_params_details
566 std::size_t... Indexes >
572 std::index_sequence<Indexes...> )
574 return std::forward<F>(what)(
576 std::get<Indexes>(std::forward<Tuple>(params))... );
589template<
typename F,
typename Extra_Data,
typename Tuple >
597 std::forward<F>(what),
599 std::forward<Tuple>(params),
600 std::make_index_sequence<
601 std::tuple_size< std::remove_reference_t<Tuple> >::value
620 typename Target_Type,
621 typename Subitems_Tuple >
623 :
public ep::impl::produce_t< Target_Type, Subitems_Tuple >
625 using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
628 using base_type_t::base_type_t;
630 template<
typename User_Type,
typename Handler >
636 typename base_type_t::result_type & type )
688template<
typename... Args >
694 using result_tuple_type =
typename dsl_processor::result_tuple;
695 using subclauses_tuple_type =
typename dsl_processor::clauses_tuple;
699 subclauses_tuple_type >;
701 return producer_type{
702 subclauses_tuple_type{ std::forward<Args>(args)... }
742template<
typename... Args >
748 using result_tuple_type =
typename dsl_processor::result_tuple;
749 using subclauses_tuple_type =
typename dsl_processor::clauses_tuple;
753 subclauses_tuple_type >;
755 return producer_type{
756 subclauses_tuple_type{ std::forward<Args>(args)... }
804 return produce< std::string >(
855template<
typename Unescape_Traits =
945template<
typename Extra_Data_Factory >
968 using namespace easy_parser_router::impl;
972 if( path_to_inspect.size() > 1u &&
'/' == path_to_inspect.back() )
973 path_to_inspect.remove_suffix( 1u );
975 target_path_holder_t target_path{ path_to_inspect };
978 const auto r = entry->try_handle( req, target_path );
997 typename Method_Matcher,
998 typename Route_Producer,
1002 Method_Matcher && method_matcher,
1003 Route_Producer && route,
1004 Handler && handler )
1006 using namespace easy_parser_router::impl;
1008 using producer_type = std::decay_t< Route_Producer >;
1009 using handler_type = std::decay_t< Handler >;
1011 using actual_entry_type = actual_router_entry_t<
1014 auto entry = std::make_unique< actual_entry_type >(
1015 std::forward<Method_Matcher>(method_matcher),
1016 std::forward<Route_Producer>(route),
1017 std::forward<Handler>(handler) );
1019 m_entries.push_back( std::move(entry) );
1023 template<
typename Route_Producer,
typename Handler >
1026 Route_Producer && route,
1027 Handler && handler )
1031 std::forward<Route_Producer>(route),
1032 std::forward<Handler>(handler) );
1036 template<
typename Route_Producer,
typename Handler >
1039 Route_Producer && route,
1040 Handler && handler )
1043 http_method_delete(),
1044 std::forward<Route_Producer>(route),
1045 std::forward<Handler>(handler) );
1049 template<
typename Route_Producer,
typename Handler >
1052 Route_Producer && route,
1053 Handler && handler )
1057 std::forward<Route_Producer>(route),
1058 std::forward<Handler>(handler) );
1062 template<
typename Route_Producer,
typename Handler >
1065 Route_Producer && route,
1066 Handler && handler )
1070 std::forward<Route_Producer>(route),
1071 std::forward<Handler>(handler) );
1075 template<
typename Route_Producer,
typename Handler >
1078 Route_Producer && route,
1079 Handler && handler )
1083 std::forward<Route_Producer>(route),
1084 std::forward<Handler>(handler) );
An actual implementation of router_entry interface.
Producer m_producer
Parser of a route and producer of argument(s) for request handler.
typename router_entry_t< Extra_Data >::actual_request_handle_t actual_request_handle_t
actual_router_entry_t(Method_Matcher &&method_matcher, Producer_Arg &&producer, Handler_Arg &&handler)
Handler m_handler
Request handler to be used.
RESTINIO_NODISCARD expected_t< request_handling_status_t, no_match_t > try_handle(const actual_request_handle_t &req, target_path_holder_t &target_path) const override
An attempt to match a request against the route.
restinio::router::impl::buffered_matcher_holder_t m_method_matcher
HTTP method to match.
An implementation of a producer for path_to_params case.
static RESTINIO_NODISCARD auto invoke_handler(const generic_request_handle_t< User_Type > &req, Handler &&handler, typename base_type_t::result_type &type)
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
An implementation of a producer for path_to_tuple case.
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
static RESTINIO_NODISCARD auto invoke_handler(const generic_request_handle_t< Extra_Data > &req, Handler &&handler, typename base_type_t::result_type &type)
An interface for one entry of easy_parser-based router.
virtual RESTINIO_NODISCARD expected_t< request_handling_status_t, no_match_t > try_handle(const actual_request_handle_t &req, target_path_holder_t &target_path) const =0
An attempt to match a request against the route.
virtual ~router_entry_t()=default
generic_request_handle_t< Extra_Data > actual_request_handle_t
A special clause type for case when exact_fixed_size_fragment_producer should be used without storing...
ep::impl::exact_fixed_size_fragment_producer_t< Size > producer_t
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
ep::impl::any_value_skipper_t consumer_t
special_exact_fixed_size_fragment_clause_t(const char(&fragment)[Size])
A special clause type for case when exact_fragment_producer should be used without storing its value.
special_exact_fragment_clause_t(string_view_t value)
ep::impl::any_value_skipper_t consumer_t
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
special_exact_fragment_clause_t(std::string value)
ep::impl::exact_fragment_producer_t producer_t
A special case of produce-consume clause where the produced value is stored into a tuple.
ep::impl::tuple_item_consumer_t< Index > consumer_t
static RESTINIO_NODISCARD Producer make_producer(Producer_Arg &&producer)
ep::impl::consume_value_clause_t< Producer, consumer_t > base_type_t
special_produce_tuple_item_clause_t(Producer_Arg &&producer)
A generic request router that uses easy_parser for matching requests with handlers.
void add_handler(Method_Matcher &&method_matcher, Route_Producer &&route, Handler &&handler)
typename Extra_Data_Factory::data_t extra_data_t
generic_request_handle_t< extra_data_t > actual_request_handle_t
generic_easy_parser_router_t & operator=(generic_easy_parser_router_t &&)=default
void http_get(Route_Producer &&route, Handler &&handler)
Set handler for HTTP GET request.
void http_head(Route_Producer &&route, Handler &&handler)
Set handler for HTTP HEAD request.
void non_matched_request_handler(generic_non_matched_request_handler_t< extra_data_t > nmrh)
Set handler for requests that don't match any route.
generic_easy_parser_router_t & operator=(const generic_easy_parser_router_t &)=delete
generic_non_matched_request_handler_t< extra_data_t > m_non_matched_request_handler
Handler that is called for requests that don't match any route.
void http_delete(Route_Producer &&route, Handler &&handler)
Set handler for HTTP DELETE request.
generic_easy_parser_router_t(generic_easy_parser_router_t &&)=default
generic_easy_parser_router_t()=default
std::vector< easy_parser_router::impl::router_entry_unique_ptr_t< extra_data_t > > entries_container_t
void http_post(Route_Producer &&route, Handler &&handler)
Set handler for HTTP POST request.
entries_container_t m_entries
generic_easy_parser_router_t(const generic_easy_parser_router_t &)=delete
void http_put(Route_Producer &&route, Handler &&handler)
Set handler for HTTP PUT request.
RESTINIO_NODISCARD request_handling_status_t operator()(actual_request_handle_t req) const
A special class that allows to hold a copy of small-size method_matchers or a pointer to dynamically ...
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.
#define RESTINIO_NODISCARD
An very small, simple and somewhat limited implementation of recursive-descent parser.
Stuff related to method_matchers.
RESTINIO_NODISCARD auto any_symbol_if_not_p(char sentinel) noexcept
A factory function to create a any_symbol_if_not_producer.
RESTINIO_NODISCARD expected_t< typename Producer::result_type, parse_error_t > try_parse(string_view_t from, Producer producer)
Perform the parsing of the specified content by using specified value producer.
RESTINIO_NODISCARD auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
constexpr std::size_t N
A special marker that means infinite repetitions.
RESTINIO_NODISCARD auto to_container()
A factory function to create a to_container_consumer.
typename detect_result_tuple< Args_Type_List >::type detect_result_tuple_t
typename make_clauses_types< Args_Type_List >::type make_clauses_types_t
decltype(auto) call_with_tuple_impl(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &¶ms, std::index_sequence< Indexes... >)
decltype(auto) call_with_tuple(F &&what, const generic_request_handle_t< Extra_Data > &req, Tuple &¶ms)
A helper function to call a request-handler with a tuple.
std::unique_ptr< router_entry_t< Extra_Data > > router_entry_unique_ptr_t
An alias for unique_ptr of router_entry.
RESTINIO_NODISCARD auto path_to_params(Args &&...args)
Describe a route for a handler that accepts params from the route in form of a list of separate argum...
RESTINIO_NODISCARD auto path_fragment_p(char separator='/')
A factory that creates a string-producer that extracts a sequence on symbols until the separator will...
RESTINIO_NODISCARD auto unescape()
A factory for unescape_transformer.
RESTINIO_NODISCARD auto path_to_tuple(Args &&...args)
Describe a route for a handler that accepts params from the route in form of a tuple.
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.
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.
nonstd::expected< T, E > expected_t
The definition of the non_matched_request_handler type.
To< Results..., typename H::result_type > type
meta::head_of_t< Sources... > head_type
typename clauses_type_maker< meta::tail_of_t< Sources... >, To< Results..., typename one_clause_type::clause_type >, one_clause_type::next_index >::type type
meta::rename_t< typename result_tuple_detector< Args_Type_List, meta::type_list<> >::type, std::tuple > type
meta::rename_t< typename clauses_type_maker< Args_Type_List, meta::type_list<>, 0u >::type, std::tuple > type
static constexpr std::size_t next_index
typename result_tuple_detector< meta::tail_of_t< Sources... >, typename add_type_if_necessary< meta::head_of_t< Sources... >, To< Results... > >::type >::type type
A special analog of std::decay meta-function that is handles array differently.
std::remove_reference_t< T > U
typename std::conditional< std::is_array< U >::value, U, std::remove_cv_t< U > >::type type
The main meta-function for processing route DSL.
dsl_details::make_clauses_types_t< arg_types > clauses_tuple
dsl_details::detect_result_tuple_t< arg_types > result_tuple
meta::transform_t< dsl_details::special_decay, meta::type_list< Args... > > arg_types
Helper type to indicate a negative match attempt.
virtual RESTINIO_NODISCARD bool match(const http_method_id_t &method) const noexcept=0
Is the specified method can be applied to a route?
The default traits for escaping and unexcaping symbols in a query string.
Implementation of target_path_holder helper class.