Skip to content
Download

query


mach::Request::query<T>

Returns a query parameter converted to a specified type.

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

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

The query parameter value converted to T, or std::nullopt if the query parameter does not exist or cannot be converted to T.

Parameter Description
T The type to convert the parameter to.
Parameter Description
name The name of the query parameter to return.
Exception Condition
std::bad_alloc Thrown if memory allocation fails during conversion.

Query parameter names are case-sensitive.

This function is thread-safe.

if (auto page = request().query<int>("page")) {
// Use *page...
}
Name Description
query Returns a query parameter.
containsQuery Checks whether the request contains a query parameter.