Go to the documentation of this file.
28 namespace easy_parser_router
91 template<
typename Producer,
typename Handler >
105 typename Method_Matcher,
106 typename Producer_Arg,
107 typename Handler_Arg >
109 Method_Matcher && method_matcher,
110 Producer_Arg && producer,
111 Handler_Arg && handler )
112 :
m_producer{ std::forward<Producer_Arg>(producer) }
113 ,
m_handler{ std::forward<Handler_Arg>(handler) }
131 return Producer::invoke_handler( req,
m_handler, *parse_result );
148 template<
typename Unescape_Traits >
158 return restinio::utils::unescape_percent_encoding< Unescape_Traits >(
172 template<
typename Producer, std::
size_t Index >
174 :
public ep::impl::consume_value_clause_t<
176 ep::impl::tuple_item_consumer_t<Index> >
185 template<
typename Producer_Arg >
190 return { std::forward<Producer_Arg>(producer) };
194 template<
typename Producer_Arg >
215 template< std::
size_t Size >
217 :
public ep::impl::consume_value_clause_t<
218 ep::impl::exact_fixed_size_fragment_producer_t<Size>,
219 ep::impl::any_value_skipper_t >
221 using producer_t = ep::impl::exact_fixed_size_fragment_producer_t<Size>;
230 const char (&fragment)[Size] )
249 :
public ep::impl::consume_value_clause_t<
250 ep::impl::exact_fragment_producer_t,
251 ep::impl::any_value_skipper_t >
267 producer_t{ std::string{ value.data(), value.size() } },
272 namespace dsl_details
276 template<
typename H,
typename R,
bool Is_Producer >
281 template<
class...>
class To,
282 typename... Results >
290 template<
class...>
class To,
291 typename... Results >
294 using type = To<Results...,
typename H::result_type>;
298 template<
typename H,
typename R >
304 template<
typename From,
typename To >
309 template<
class...>
class From,
311 template<
class...>
class To,
312 typename... Results >
324 template<
class...>
class From,
325 template<
class...>
class To,
326 typename... Results >
333 template<
typename Args_Type_List >
343 template<
typename Args_Type_List >
355 template<
typename T,
bool Is_Producer, std::
size_t Current_Index >
362 template< std::
size_t Size, std::
size_t Current_Index >
369 template< std::
size_t Current_Index >
376 template< std::
size_t Current_Index >
383 template<
typename T, std::
size_t Current_Index >
387 static constexpr std::size_t
next_index = Current_Index + 1u;
394 template<
typename From,
typename To, std::
size_t Current_Index >
398 template<
class...>
class From,
400 template<
class...>
class To,
402 std::size_t Current_Index >
410 ep::impl::is_producer_v<head_type>,
417 one_clause_type::next_index >
::type;
421 template<
class...>
class From,
422 template<
class...>
class To,
424 std::size_t Current_Index >
432 template<
typename Args_Type_List >
443 template<
typename Args_Type_List >
463 template<
typename T >
467 using U = std::remove_reference_t<T>;
470 using type =
typename std::conditional<
471 std::is_array<U>::value,
495 template<
typename... Args >
498 static_assert( 0u !=
sizeof...(Args),
"Args can't be an empty list" );
520 typename Target_Type,
521 typename Subitems_Tuple >
523 :
public ep::impl::produce_t< Target_Type, Subitems_Tuple >
525 using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
528 using base_type_t::base_type_t;
530 template<
typename Handler >
536 typename base_type_t::result_type & type )
538 return handler( req, type );
542 namespace path_to_params_details
548 std::size_t... Indexes >
554 std::index_sequence<Indexes...> )
556 return std::forward<F>(what)(
558 std::get<Indexes>(std::forward<Tuple>(params))... );
571 template<
typename F,
typename Tuple >
579 std::forward<F>(what),
581 std::forward<Tuple>(params),
582 std::make_index_sequence<
583 std::tuple_size< std::remove_reference_t<Tuple> >::value
602 typename Target_Type,
603 typename Subitems_Tuple >
605 :
public ep::impl::produce_t< Target_Type, Subitems_Tuple >
607 using base_type_t = ep::impl::produce_t< Target_Type, Subitems_Tuple >;
610 using base_type_t::base_type_t;
612 template<
typename Handler >
618 typename base_type_t::result_type & type )
670 template<
typename... Args >
676 using result_tuple_type =
typename dsl_processor::result_tuple;
677 using subclauses_tuple_type =
typename dsl_processor::clauses_tuple;
681 subclauses_tuple_type >;
683 return producer_type{
684 subclauses_tuple_type{ std::forward<Args>(args)... }
724 template<
typename... Args >
730 using result_tuple_type =
typename dsl_processor::result_tuple;
731 using subclauses_tuple_type =
typename dsl_processor::clauses_tuple;
735 subclauses_tuple_type >;
737 return producer_type{
738 subclauses_tuple_type{ std::forward<Args>(args)... }
786 return produce< std::string >(
837 template<
typename Unescape_Traits =
924 using namespace easy_parser_router::impl;
928 if( path_to_inspect.size() > 1u &&
'/' == path_to_inspect.back() )
929 path_to_inspect.remove_suffix( 1u );
932 for(
const auto & entry : m_entries )
934 const auto r = entry->try_handle( req, target_path );
942 if( m_non_matched_request_handler )
946 return m_non_matched_request_handler(
std::move( req ) );
953 typename Method_Matcher,
954 typename Route_Producer,
958 Method_Matcher && method_matcher,
959 Route_Producer && route,
962 using namespace easy_parser_router::impl;
964 using producer_type = std::decay_t< Route_Producer >;
965 using handler_type = std::decay_t< Handler >;
967 using actual_entry_type = actual_router_entry_t<
968 producer_type, handler_type >;
970 auto entry = std::make_unique< actual_entry_type >(
971 std::forward<Method_Matcher>(method_matcher),
972 std::forward<Route_Producer>(route),
973 std::forward<Handler>(handler) );
979 template<
typename Route_Producer,
typename Handler >
982 Route_Producer && route,
987 std::forward<Route_Producer>(route),
988 std::forward<Handler>(handler) );
992 template<
typename Route_Producer,
typename Handler >
995 Route_Producer && route,
999 http_method_delete(),
1000 std::forward<Route_Producer>(route),
1001 std::forward<Handler>(handler) );
1005 template<
typename Route_Producer,
typename Handler >
1008 Route_Producer && route,
1009 Handler && handler )
1013 std::forward<Route_Producer>(route),
1014 std::forward<Handler>(handler) );
1018 template<
typename Route_Producer,
typename Handler >
1021 Route_Producer && route,
1022 Handler && handler )
1026 std::forward<Route_Producer>(route),
1027 std::forward<Handler>(handler) );
1031 template<
typename Route_Producer,
typename Handler >
1034 Route_Producer && route,
1035 Handler && handler )
1039 std::forward<Route_Producer>(route),
1040 std::forward<Handler>(handler) );
1047 m_non_matched_request_handler=
std::move( nmrh );
1052 std::vector< easy_parser_router::impl::router_entry_unique_ptr_t >;
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.
typename make_clauses_types< Args_Type_List >::type make_clauses_types_t
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
#define RESTINIO_NODISCARD
dsl_details::detect_result_tuple_t< arg_types > result_tuple
A special class that allows to hold a copy of small-size method_matchers or a pointer to dynamically ...
void non_matched_request_handler(non_matched_request_handler_t nmrh)
Set handler for requests that don't match any route.
void http_get(Route_Producer &&route, Handler &&handler)
Set handler for HTTP GET request.
special_exact_fragment_clause_t(std::string value)
static RESTINIO_NODISCARD Producer make_producer(Producer_Arg &&producer)
typename std::conditional< std::is_array< U >::value, U, std::remove_cv_t< U > >::type type
std::vector< easy_parser_router::impl::router_entry_unique_ptr_t > entries_container_t
restinio::router::impl::buffered_matcher_holder_t m_method_matcher
HTTP method to match.
void http_delete(Route_Producer &&route, Handler &&handler)
Set handler for HTTP DELETE request.
void add_handler(Method_Matcher &&method_matcher, Route_Producer &&route, Handler &&handler)
RESTINIO_NODISCARD expected_t< request_handling_status_t, no_match_t > try_handle(const request_handle_t &req, target_path_holder_t &target_path) const override
An attempt to match a request against the route.
ep::impl::produce_t< Target_Type, Subitems_Tuple > base_type_t
constexpr std::size_t N
A special marker that means infinite repetitions.
void http_head(Route_Producer &&route, Handler &&handler)
Set handler for HTTP HEAD request.
easy_parser_router_t(easy_parser_router_t &&)=default
std::remove_reference_t< T > U
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...
nonstd::string_view string_view_t
special_exact_fixed_size_fragment_clause_t(const char(&fragment)[Size])
void http_put(Route_Producer &&route, Handler &&handler)
Set handler for HTTP PUT request.
easy_parser_router_t(const easy_parser_router_t &)=delete
easy_parser_router_t & operator=(const easy_parser_router_t &)=delete
typename result_tuple_detector< meta::tail_of_t< Sources... >, typename add_type_if_necessary< meta::head_of_t< Sources... >, To< Results... > >::type >::type type
virtual RESTINIO_NODISCARD bool match(const http_method_id_t &method) const noexcept=0
Is the specified method can be applied to a route?
meta::transform_t< dsl_details::special_decay, meta::type_list< Args... > > arg_types
Handler m_handler
Request handler to be used.
Implementation of target_path_holder helper class.
Helper class for holding a unique instance of char array with target_path value.
The default traits for escaping and unexcaping symbols in a query string.
ep::impl::any_value_skipper_t consumer_t
RESTINIO_NODISCARD auto any_symbol_if_not_p(char sentinel) noexcept
A factory function to create a any_symbol_if_not_producer.
special_produce_tuple_item_clause_t(Producer_Arg &&producer)
A request router that uses easy_parser for matching requests with handlers.
special_exact_fragment_clause_t(string_view_t value)
A special clause type for case when exact_fixed_size_fragment_producer should be used without storing...
request_handling_status_t
Request handling status.
An implementation of a producer for path_to_tuple case.
ep::impl::exact_fragment_producer_t producer_t
easy_parser_router_t & operator=(easy_parser_router_t &&)=default
An very small, simple and somewhat limited implementation of recursive-descent parser.
An implementation of a producer for path_to_params case.
Producer m_producer
Parser of a route and producer of argument(s) for request handler.
An interface for one entry of easy_parser-based router.
ep::impl::exact_fixed_size_fragment_producer_t< Size > producer_t
static constexpr std::size_t next_index
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
entries_container_t m_entries
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.
ep::impl::consume_value_clause_t< producer_t, consumer_t > base_type_t
A special clause type for case when exact_fragment_producer should be used without storing its value.
ep::impl::tuple_item_consumer_t< Index > consumer_t
std::function< request_handling_status_t(request_handle_t) > non_matched_request_handler_t
RESTINIO_NODISCARD request_handling_status_t operator()(request_handle_t req) const
nonstd::expected< T, E > expected_t
ep::impl::consume_value_clause_t< Producer, consumer_t > base_type_t
static RESTINIO_NODISCARD auto invoke_handler(const request_handle_t &req, Handler &&handler, typename base_type_t::result_type &type)
An actual implementation of router_entry interface.
meta::rename_t< typename clauses_type_maker< Args_Type_List, meta::type_list<>, 0u >::type, std::tuple > type
To< Results..., typename H::result_type > type
RESTINIO_NODISCARD auto to_container()
A factory function to create a to_container_consumer.
Stuff related to method_matchers.
virtual ~router_entry_t()=default
The main meta-function for processing route DSL.
meta::rename_t< typename result_tuple_detector< Args_Type_List, meta::type_list<> >::type, std::tuple > type
A special case of produce-consume clause where the produced value is stored into a tuple.
RESTINIO_NODISCARD auto unescape()
A factory for unescape_transformer.
std::unique_ptr< router_entry_t > router_entry_unique_ptr_t
An alias for unique_ptr of router_entry.
static RESTINIO_NODISCARD auto invoke_handler(const request_handle_t &req, Handler &&handler, typename base_type_t::result_type &type)
virtual RESTINIO_NODISCARD expected_t< request_handling_status_t, no_match_t > try_handle(const request_handle_t &req, target_path_holder_t &target_path) const =0
An attempt to match a request against the route.
non_matched_request_handler_t m_non_matched_request_handler
Handler that is called for requests that don't match any route.
RESTINIO_NODISCARD string_view_t view() const noexcept
Get access to the value of target_path.
void http_post(Route_Producer &&route, Handler &&handler)
Set handler for HTTP POST request.
typename detect_result_tuple< Args_Type_List >::type detect_result_tuple_t
std::shared_ptr< request_t > request_handle_t
Request handler, that is the type for calling request handlers.
meta::head_of_t< Sources... > head_type
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...
A special analog of std::decay meta-function that is handles array differently.
decltype(auto) call_with_tuple_impl(F &&what, const request_handle_t &req, Tuple &¶ms, std::index_sequence< Indexes... >)
constexpr request_handling_status_t request_rejected() noexcept
dsl_details::make_clauses_types_t< arg_types > clauses_tuple
typename clauses_type_maker< meta::tail_of_t< Sources... >, To< Results..., typename one_clause_type::clause_type >, one_clause_type::next_index >::type type
actual_router_entry_t(Method_Matcher &&method_matcher, Producer_Arg &&producer, Handler_Arg &&handler)
ep::impl::any_value_skipper_t consumer_t
decltype(auto) call_with_tuple(F &&what, const request_handle_t &req, Tuple &¶ms)
A helper function to call a request-handler with a tuple.
restinio::router::impl::target_path_holder_t target_path_holder_t
The definition of the non_matched_request_handler type.
Helper type to indicate a negative match attempt.
easy_parser_router_t()=default
RESTINIO_NODISCARD auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.