RESTinio
Namespaces | Functions
restinio::router::easy_parser_router Namespace Reference

Namespaces

namespace  impl
 

Functions

template<typename... Args>
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. More...
 
template<typename... Args>
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 arguments. More...
 
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 be found. More...
 
template<typename Unescape_Traits = restinio::utils::restinio_default_unescape_traits>
RESTINIO_NODISCARD auto unescape ()
 A factory for unescape_transformer. More...
 

Function Documentation

◆ path_fragment_p()

RESTINIO_NODISCARD auto restinio::router::easy_parser_router::path_fragment_p ( char  separator = '/')
inline

A factory that creates a string-producer that extracts a sequence on symbols until the separator will be found.

Usage example:

router->add_handler(http_method_get(),
// Route for '/film/:author/:title'
"/film/",
"/",
),
const std::string & author,
const std::string & title) {...});
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...
std::shared_ptr< request_t > request_handle_t
An alias for handle for incoming request without additional extra-data.

By default the separator is '/', by it can be changed by separator argument:

router->add_handler(http_method_get(),
// Route for '/user-group'
"/",
),
const std::string & user,
const std::string & group) {...});
Since
v.0.6.6

Definition at line 805 of file easy_parser_router.hpp.

◆ path_to_params()

template<typename... Args>
RESTINIO_NODISCARD auto restinio::router::easy_parser_router::path_to_params ( Args &&...  args)

Describe a route for a handler that accepts params from the route in form of a list of separate arguments.

Usage example:

router->add_handler(http_method_get(),
path_to_params("/api/v1/users/", user_id_parser),
[](const auto & req, const auto & uid) {
...
});
router->add_handler(http_method_get(),
"/api/v1/books/", book_id_parser,
"/versions/", version_id_parser),
[](const auto & req, const auto & book_id, const auto & ver_id) {
...
});

Please note that a route can contain no params at all. In that case the request handler will receive just one parameter: a requst_handle.

router->add_handler(http_method_get(),
path_to_params("/api/v1/books"),
[](const auto & req) {
...
});
Since
v.0.6.6

Definition at line 748 of file easy_parser_router.hpp.

◆ path_to_tuple()

template<typename... Args>
RESTINIO_NODISCARD auto restinio::router::easy_parser_router::path_to_tuple ( Args &&...  args)

Describe a route for a handler that accepts params from the route in form of a tuple.

Usage example:

router->add_handler(http_method_get(),
path_to_tuple("/api/v1/users/", user_id_parser),
[](const auto & req, const auto & params) {
auto uid = std::get<0>(params);
...
});
router->add_handler(http_method_get(),
"/api/v1/books/", book_id_parser,
"/versions/", version_id_parser),
[](const auto & req, const auto & params) {
auto book_id = std::get<0>(params);
auto ver_id = std::get<1>(params);
...
});
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.

Please note that a route can contain no params at all. In that case an empty tuple will be passed as an argument to the request handler:

router->add_handler(http_method_get(),
path_to_tuple("/api/v1/books"),
[](const auto & req, auto params) {
static_assert(
std::is_same<std::tuple<>, decltype(params)>::value,
"type std::tuple<> is expected");
...
});
Since
v.0.6.6

Definition at line 694 of file easy_parser_router.hpp.

◆ unescape()

template<typename Unescape_Traits = restinio::utils::restinio_default_unescape_traits>
RESTINIO_NODISCARD auto restinio::router::easy_parser_router::unescape ( )

A factory for unescape_transformer.

The unescape_transformer performs unescaping of percent-encoded string.

Usage example:

router->add_handler(http_method_get(),
// Route for '/film/:author/:title'
"/film/",
"/",
),
const std::string & author,
const std::string & title) {...});
RESTINIO_NODISCARD auto unescape()
A factory for unescape_transformer.
Note
This function can be parametrized by Unescape_Traits type:
struct film_by_athor_and_title { std::string author, title };
router->add_handler(http_method_get(),
// Route for '/film/:author/:title'
"/film/",
>> epr::unescape<restinio::utils::javascript_compatible_unescape_traits>(),
"/",
>> epr::unescape<restinio::utils::javascript_compatible_unescape_traits>()
),
const std::string & author,
const std::string & title) {...});
Since
v.0.6.6

Definition at line 862 of file easy_parser_router.hpp.