routeParam
mach::Request::routeParam<T>
Returns a route parameter converted to a specified type.
Description
Section titled “Description”Returns the value of the route parameter with the specified name, converted to the specified type.
Syntax
Section titled “Syntax”template <typename T>[[nodiscard]] T routeParam(std::string_view name) const;Return Value
Section titled “Return Value”The converted route parameter value.
Template Parameters
Section titled “Template Parameters”| Parameter | Description |
|---|---|
T |
The type to convert the parameter to. |
Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
name |
The name of the route parameter to return. |
Exceptions
Section titled “Exceptions”| 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. |
Remarks
Section titled “Remarks”Route parameter names are case-sensitive.
Thread Safety
Section titled “Thread Safety”This function is thread-safe.
Example
Section titled “Example”auto id = request().routeParam<int>("id");See Also
Section titled “See Also”| Name | Description |
|---|---|
routeParam |
Returns a route parameter. |