query
mach::Request::query<T>
Returns a query parameter converted to a specified type.
Description
Section titled “Description”Returns the value of the query parameter with the specified name, converted to the specified type.
Syntax
Section titled “Syntax”template <typename T>[[nodiscard]] std::optional<T> query(std::string_view name) const;Return Value
Section titled “Return Value”The query parameter value converted to T, or std::nullopt if the query parameter does not exist or cannot be converted to T.
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 query parameter to return. |
Exceptions
Section titled “Exceptions”| Exception | Condition |
|---|---|
std::bad_alloc |
Thrown if memory allocation fails during conversion. |
Remarks
Section titled “Remarks”Query parameter names are case-sensitive.
Thread Safety
Section titled “Thread Safety”This function is thread-safe.
Example
Section titled “Example”if (auto page = request().query<int>("page")) { // Use *page...}See Also
Section titled “See Also”| Name | Description |
|---|---|
query |
Returns a query parameter. |
containsQuery |
Checks whether the request contains a query parameter. |