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:

namespace epr = restinio::router::easy_parser_router;
router->add_handler(http_method_get(),
// Route for '/film/:author/:title'
path_to_params(
"/film/",
epr::path_fragment_p(),
"/",
epr::path_fragment_p()
),
[](const restinio::request_handle_t & req,
const std::string & author,
const std::string & title) {...});
restinio::router::easy_parser_router
Definition: easy_parser_router.hpp:29
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:748
restinio::router::easy_parser_router::path_fragment_p
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...
Definition: easy_parser_router.hpp:805
restinio::request_handle_t
std::shared_ptr< request_t > request_handle_t
An alias for handle for incoming request without additional extra-data.
Definition: request_handler.hpp:463

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

namespace epr = restinio::router::easy_parser_router;
router->add_handler(http_method_get(),
// Route for '/user-group'
path_to_params(
"/",
epr::path_fragment_p('-'),
epr::path_fragment_p()
),
[](const restinio::request_handle_t & req,
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(),
path_to_params(
"/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(),
path_to_tuple(
"/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::router::easy_parser_router::path_to_tuple
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.
Definition: easy_parser_router.hpp:694

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:

namespace epr = restinio::router::easy_parser_router;
router->add_handler(http_method_get(),
// Route for '/film/:author/:title'
path_to_params(
"/film/",
epr::path_fragment_p() >> epr::unescape(),
"/",
epr::path_fragment_p() >> epr::unescape()
),
[](const restinio::request_handle_t & req,
const std::string & author,
const std::string & title) {...});
restinio::router::easy_parser_router::unescape
RESTINIO_NODISCARD auto unescape()
A factory for unescape_transformer.
Definition: easy_parser_router.hpp:862

Note
  This function can be parametrized by Unescape_Traits type:
  namespace epr = restinio::router::easy_parser_router;
  struct film_by_athor_and_title { std::string author, title };
  router->add_handler(http_method_get(),
  // Route for '/film/:author/:title'
  path_to_params(
  "/film/",
  epr::path_fragment_p()
  >> epr::unescape<restinio::utils::javascript_compatible_unescape_traits>(),
  "/",
  epr::path_fragment_p()
  >> epr::unescape<restinio::utils::javascript_compatible_unescape_traits>()
  ),
  [](const restinio::request_handle_t & req,
  const std::string & author,
  const std::string & title) {...});

Since
  v.0.6.6

Definition at line 862 of file easy_parser_router.hpp.