Skip to content
Download

routeParam

mach::Request::routeParam<T>

Returns a route parameter converted to a specified type.

Returns the value of the route parameter with the specified name, converted to the specified type.

template <typename T>
[[nodiscard]] T routeParam(std::string_view name) const;

The converted route parameter value.

Parameter Description
T The type to convert the parameter to.
Parameter Description
name The name of the route parameter to return.
Exception Condition
std::bad_alloc Thrown if memory allocation fails during conversion.
std::out_of_range Thrown if the specified route parameter does not exist.
std::invalid_argument Thrown if the route parameter value cannot be converted to T.

Route parameter names are case-sensitive.

This function is thread-safe.

auto id = request().routeParam<int>("id");
Name Description
routeParam Returns a route parameter.