RESTinio
Public Member Functions | Private Types | Private Attributes | List of all members
restinio::router::easy_parser_router_t Class Reference

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

#include <easy_parser_router.hpp>

Public Member Functions

 easy_parser_router_t ()=default
 
 easy_parser_router_t (const easy_parser_router_t &)=delete
 
easy_parser_router_toperator= (const easy_parser_router_t &)=delete
 
 easy_parser_router_t (easy_parser_router_t &&)=default
 
easy_parser_router_toperator= (easy_parser_router_t &&)=default
 
RESTINIO_NODISCARD request_handling_status_t operator() (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 (non_matched_request_handler_t nmrh)
 Set handler for requests that don't match any route. More...
 

Private Types

using entries_container_t = std::vector< easy_parser_router::impl::router_entry_unique_ptr_t >
 

Private Attributes

entries_container_t m_entries
 
non_matched_request_handler_t m_non_matched_request_handler
 Handler that is called for requests that don't match any route. More...
 

Detailed Description

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

Usage example:

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 request_handler_t = router_t;
}
...
restinio::run(
restinio::on_this_thread<traits_t>()
.request_handler(make_router)
...
);
Since
v.0.6.6

Definition at line 907 of file easy_parser_router.hpp.

Member Typedef Documentation

◆ entries_container_t

Definition at line 1051 of file easy_parser_router.hpp.

Constructor & Destructor Documentation

◆ easy_parser_router_t() [1/3]

restinio::router::easy_parser_router_t::easy_parser_router_t ( )
default

◆ easy_parser_router_t() [2/3]

restinio::router::easy_parser_router_t::easy_parser_router_t ( const easy_parser_router_t )
delete

◆ easy_parser_router_t() [3/3]

restinio::router::easy_parser_router_t::easy_parser_router_t ( easy_parser_router_t &&  )
default

Member Function Documentation

◆ add_handler()

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

Definition at line 957 of file easy_parser_router.hpp.

◆ http_delete()

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

Set handler for HTTP DELETE request.

Definition at line 994 of file easy_parser_router.hpp.

◆ http_get()

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

Set handler for HTTP GET request.

Definition at line 981 of file easy_parser_router.hpp.

◆ http_head()

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

Set handler for HTTP HEAD request.

Definition at line 1007 of file easy_parser_router.hpp.

◆ http_post()

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

Set handler for HTTP POST request.

Definition at line 1020 of file easy_parser_router.hpp.

◆ http_put()

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

Set handler for HTTP PUT request.

Definition at line 1033 of file easy_parser_router.hpp.

◆ non_matched_request_handler()

void restinio::router::easy_parser_router_t::non_matched_request_handler ( non_matched_request_handler_t  nmrh)
inline

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

Definition at line 1045 of file easy_parser_router.hpp.

◆ operator()()

RESTINIO_NODISCARD request_handling_status_t restinio::router::easy_parser_router_t::operator() ( request_handle_t  req) const
inline

Definition at line 922 of file easy_parser_router.hpp.

◆ operator=() [1/2]

easy_parser_router_t& restinio::router::easy_parser_router_t::operator= ( const easy_parser_router_t )
delete

◆ operator=() [2/2]

easy_parser_router_t& restinio::router::easy_parser_router_t::operator= ( easy_parser_router_t &&  )
default

Member Data Documentation

◆ m_entries

entries_container_t restinio::router::easy_parser_router_t::m_entries
private

Definition at line 1054 of file easy_parser_router.hpp.

◆ m_non_matched_request_handler

non_matched_request_handler_t restinio::router::easy_parser_router_t::m_non_matched_request_handler
private

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

Definition at line 1057 of file easy_parser_router.hpp.


The documentation for this class was generated from the following file:
restinio::traits_t
Definition: traits.hpp:33
restinio::router::easy_parser_router_t
A request router that uses easy_parser for matching requests with handlers.
Definition: easy_parser_router.hpp:908
restinio::router::any_of_methods
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...
Definition: method_matcher.hpp:417
restinio::router::easy_parser_router::path_to_params
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...
Definition: easy_parser_router.hpp:727
restinio::router::none_of_methods
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...
Definition: method_matcher.hpp:449
restinio::router::easy_parser_router
Definition: easy_parser_router.hpp:29