RESTinio
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
restinio::router::generic_easy_parser_router_t< Extra_Data_Factory > Class Template Reference

A generic request router that uses easy_parser for matching requests with handlers. More...

#include <easy_parser_router.hpp>

Public Types

using actual_request_handle_t = generic_request_handle_t< extra_data_t >
 

Public Member Functions

 generic_easy_parser_router_t ()=default
 
 generic_easy_parser_router_t (const generic_easy_parser_router_t &)=delete
 
generic_easy_parser_router_toperator= (const generic_easy_parser_router_t &)=delete
 
 generic_easy_parser_router_t (generic_easy_parser_router_t &&)=default
 
generic_easy_parser_router_toperator= (generic_easy_parser_router_t &&)=default
 
RESTINIO_NODISCARD request_handling_status_t operator() (actual_request_handle_t req) const
 
template<typename Method_Matcher , typename Route_Producer , typename Handler >
void add_handler (Method_Matcher &&method_matcher, Route_Producer &&route, Handler &&handler)
 
template<typename Route_Producer , typename Handler >
void http_get (Route_Producer &&route, Handler &&handler)
 Set handler for HTTP GET request. More...
 
template<typename Route_Producer , typename Handler >
void http_delete (Route_Producer &&route, Handler &&handler)
 Set handler for HTTP DELETE request. More...
 
template<typename Route_Producer , typename Handler >
void http_head (Route_Producer &&route, Handler &&handler)
 Set handler for HTTP HEAD request. More...
 
template<typename Route_Producer , typename Handler >
void http_post (Route_Producer &&route, Handler &&handler)
 Set handler for HTTP POST request. More...
 
template<typename Route_Producer , typename Handler >
void http_put (Route_Producer &&route, Handler &&handler)
 Set handler for HTTP PUT request. More...
 
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. More...
 

Private Types

using extra_data_t = typename Extra_Data_Factory::data_t
 
using entries_container_t = std::vector< easy_parser_router::impl::router_entry_unique_ptr_t< extra_data_t > >
 

Private Attributes

entries_container_t m_entries
 
generic_non_matched_request_handler_t< extra_data_tm_non_matched_request_handler
 Handler that is called for requests that don't match any route. More...
 

Detailed Description

template<typename Extra_Data_Factory>
class restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >

A generic request router that uses easy_parser for matching requests with handlers.

Note
That type is intended to be used when extra-data-factory for server traits is not the default one. If your server uses the default extra-data-factory then easy_parser_router_t should be used for the simplicity.

Usage example:

struct my_extra_data_factory {
// Type of data to be incorporated into request object.
struct data_t {...};
// Factory function for data_t.
void make_within( restinio::extra_data_buffer_t<data_t> buf ) {
new(buf.get()) data_t{...};
}
};
my_extra_data_factory >;
auto make_router(...) {
auto router = std::make_unique<router_t>();
...
router->http_get(epr::path_to_params(...),
[](const auto & req, ...) {...});
router->http_post(epr::path_to_params(...),
[](const auto & req, ...) {...});
router->http_delete(epr::path_to_params(...),
[](const auto & req, ...) {...});
router->add_handler(
restinio::http_method_lock(),
[](const auto & req, ...) {...});
router->add_handler(
restinio::http_method_get(),
restinio::http_method_delete(),
restinio::http_method_post()),
[](const auto & req, ...) {...});
router->add_handler(
restinio::http_method_get(),
restinio::http_method_delete(),
restinio::http_method_post()),
[](const auto & req, ...) {...});
return router;
}
...
struct traits_t : public restinio::default_traits_t {
using extra_data_factory_t = my_extra_data_factory;
using request_handler_t = router_t;
}
...
restinio::run(
restinio::on_this_thread<traits_t>()
.request_handler(make_router)
...
);
Helper for holding a pointer to a buffer where a new object of type Extra_Data should be constructed.
RESTINIO_NODISCARD void * get() const noexcept
A generic request router that uses easy_parser for matching requests with handlers.
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 impl::fixed_size_any_of_matcher_t< sizeof...(Args) > any_of_methods(Args &&...args)
A factory function that creates a method_matcher that allows a method if it's found in the list of al...
RESTINIO_NODISCARD impl::fixed_size_none_of_matcher_t< sizeof...(Args) > none_of_methods(Args &&...args)
A factory function that creates a method_matcher that allows a method if it isn't found in the list o...
Template Parameters
Extra_Data_FactoryThe type of user-type-factory. This type should be the same as the traits::user_type_factory_t type for the server.
Since
v.0.6.6, v.0.6.13

Definition at line 949 of file easy_parser_router.hpp.

Member Typedef Documentation

◆ actual_request_handle_t

template<typename Extra_Data_Factory >
using restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::actual_request_handle_t = generic_request_handle_t< extra_data_t >

Definition at line 954 of file easy_parser_router.hpp.

◆ entries_container_t

template<typename Extra_Data_Factory >
using restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::entries_container_t = std::vector< easy_parser_router::impl::router_entry_unique_ptr_t< extra_data_t > >
private

Definition at line 1099 of file easy_parser_router.hpp.

◆ extra_data_t

template<typename Extra_Data_Factory >
using restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::extra_data_t = typename Extra_Data_Factory::data_t
private

Definition at line 951 of file easy_parser_router.hpp.

Constructor & Destructor Documentation

◆ generic_easy_parser_router_t() [1/3]

template<typename Extra_Data_Factory >
restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::generic_easy_parser_router_t ( )
default

◆ generic_easy_parser_router_t() [2/3]

template<typename Extra_Data_Factory >
restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::generic_easy_parser_router_t ( const generic_easy_parser_router_t< Extra_Data_Factory > &  )
delete

◆ generic_easy_parser_router_t() [3/3]

template<typename Extra_Data_Factory >
restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::generic_easy_parser_router_t ( generic_easy_parser_router_t< Extra_Data_Factory > &&  )
default

Member Function Documentation

◆ add_handler()

template<typename Extra_Data_Factory >
template<typename Method_Matcher , typename Route_Producer , typename Handler >
void restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::add_handler ( Method_Matcher &&  method_matcher,
Route_Producer &&  route,
Handler &&  handler 
)
inline

Definition at line 1004 of file easy_parser_router.hpp.

◆ http_delete()

template<typename Extra_Data_Factory >
template<typename Route_Producer , typename Handler >
void restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::http_delete ( Route_Producer &&  route,
Handler &&  handler 
)
inline

Set handler for HTTP DELETE request.

Definition at line 1041 of file easy_parser_router.hpp.

◆ http_get()

template<typename Extra_Data_Factory >
template<typename Route_Producer , typename Handler >
void restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::http_get ( Route_Producer &&  route,
Handler &&  handler 
)
inline

Set handler for HTTP GET request.

Definition at line 1028 of file easy_parser_router.hpp.

◆ http_head()

template<typename Extra_Data_Factory >
template<typename Route_Producer , typename Handler >
void restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::http_head ( Route_Producer &&  route,
Handler &&  handler 
)
inline

Set handler for HTTP HEAD request.

Definition at line 1054 of file easy_parser_router.hpp.

◆ http_post()

template<typename Extra_Data_Factory >
template<typename Route_Producer , typename Handler >
void restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::http_post ( Route_Producer &&  route,
Handler &&  handler 
)
inline

Set handler for HTTP POST request.

Definition at line 1067 of file easy_parser_router.hpp.

◆ http_put()

template<typename Extra_Data_Factory >
template<typename Route_Producer , typename Handler >
void restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::http_put ( Route_Producer &&  route,
Handler &&  handler 
)
inline

Set handler for HTTP PUT request.

Definition at line 1080 of file easy_parser_router.hpp.

◆ non_matched_request_handler()

template<typename Extra_Data_Factory >
void restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::non_matched_request_handler ( generic_non_matched_request_handler_t< extra_data_t nmrh)
inline

Set handler for requests that don't match any route.

Definition at line 1092 of file easy_parser_router.hpp.

◆ operator()()

template<typename Extra_Data_Factory >
RESTINIO_NODISCARD request_handling_status_t restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::operator() ( actual_request_handle_t  req) const
inline

Definition at line 969 of file easy_parser_router.hpp.

◆ operator=() [1/2]

template<typename Extra_Data_Factory >
generic_easy_parser_router_t & restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::operator= ( const generic_easy_parser_router_t< Extra_Data_Factory > &  )
delete

◆ operator=() [2/2]

template<typename Extra_Data_Factory >
generic_easy_parser_router_t & restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::operator= ( generic_easy_parser_router_t< Extra_Data_Factory > &&  )
default

Member Data Documentation

◆ m_entries

template<typename Extra_Data_Factory >
entries_container_t restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::m_entries
private

Definition at line 1103 of file easy_parser_router.hpp.

◆ m_non_matched_request_handler

template<typename Extra_Data_Factory >
generic_non_matched_request_handler_t< extra_data_t > restinio::router::generic_easy_parser_router_t< Extra_Data_Factory >::m_non_matched_request_handler
private

Handler that is called for requests that don't match any route.

Definition at line 1107 of file easy_parser_router.hpp.


The documentation for this class was generated from the following file: