Skip to content
Download

mapPost

mach::ControllerBuilder::mapPost

Registers a POST handler.

Registers a POST endpoint for the controller.

// (1)
template <typename THandler>
ControllerBuilder<TController>& mapPost(std::string_view pattern, THandler&& handler);
// (2)
template <typename THandler>
ControllerBuilder<TController>& mapPost(THandler&& handler);

A reference to the current ControllerBuilder instance.

Parameter Description
THandler The type of the endpoint handler.
Parameter Description
pattern The route pattern to map.
handler The handler invoked for the endpoint.
Parameter Description
handler The handler invoked for the endpoint.
Exception Condition
std::logic_error Thrown if a route with the same method and pattern has already been registered.

In overload (2), the route pattern defaults to the controller’s route.

This method is not thread-safe and should only be called during controller configuration, before the application starts handling requests.

controller.mapPost("/users", &UserController::createUser);
controller.mapPost(&UserController::createUser);
Name Description
mapGet Registers a GET handler.
mapPut Registers a PUT handler.
mapPatch Registers a PATCH handler.
mapDelete Registers a DELETE handler.
mapHead Registers a HEAD handler.