mapGet
mach::ControllerBuilder::mapGet
Registers a GET handler.
Description
Section titled “Description”Registers a GET endpoint for the controller.
Syntax
Section titled “Syntax”// (1)template <typename THandler>ControllerBuilder<TController>& mapGet(std::string_view pattern, THandler&& handler);
// (2)template <typename THandler>ControllerBuilder<TController>& mapGet(THandler&& handler);Return Value
Section titled “Return Value”A reference to the current ControllerBuilder instance.
Template Parameters
Section titled “Template Parameters”| Parameter | Description |
|---|---|
THandler |
The type of the endpoint handler. |
Parameters
Section titled “Parameters”Overload (1)
Section titled “Overload (1)”| Parameter | Description |
|---|---|
pattern |
The route pattern to map. |
handler |
The handler invoked for the endpoint. |
Overload (2)
Section titled “Overload (2)”| Parameter | Description |
|---|---|
handler |
The handler invoked for the endpoint. |
Exceptions
Section titled “Exceptions”| Exception | Condition |
|---|---|
std::logic_error |
Thrown if a route with the same method and pattern has already been registered. |
Remarks
Section titled “Remarks”In overload (2), the route pattern defaults to the controller’s route.
Thread Safety
Section titled “Thread Safety”This method is not thread-safe and should only be called during controller configuration, before the application starts handling requests.
Examples
Section titled “Examples”Overload (1)
Section titled “Overload (1)”controller.mapGet("/users", &UserController::getUsers);Overload (2)
Section titled “Overload (2)”controller.mapGet(&UserController::getUsers);See Also
Section titled “See Also”| Name | Description |
|---|---|
mapPost |
Registers a POST handler. |
mapPut |
Registers a PUT handler. |
mapPatch |
Registers a PATCH handler. |
mapDelete |
Registers a DELETE handler. |
mapHead |
Registers a HEAD handler. |