Skip to content
Download

mapGet

mach::App::mapGet

Registers a handler for HTTP GET requests.

Registers a handler for HTTP GET requests matching the specified route pattern.

template <typename THandler>
void mapGet(std::string_view pattern, THandler&& handler);
Name Description
pattern The route pattern to match (e.g. “/api/users”).
handler The handler invoked when a request matches the route pattern.
Exception Condition
std::logic_error Thrown if a route with the same HTTP method and route pattern has already been registered.
  • The endpoint is registered immediately when this function is called.
  • A corresponding HEAD endpoint is automatically available for every registered GET endpoint.
  • OPTIONS requests are handled automatically by the framework.

This function is not thread-safe. Concurrent route registration must be synchronized externally.

app.mapGet("/", [] {
return mach::ok();
});
Name Description
mapPost Registers a handler for HTTP POST requests.
mapPut Registers a handler for HTTP PUT requests.
mapPatch Registers a handler for HTTP PATCH requests.
mapDelete Registers a handler for HTTP DELETE requests.
mapHead Registers a handler for HTTP HEAD requests.