mapGet
mach::App::mapGet
Registers a handler for HTTP GET requests.
Description
Section titled “Description”Registers a handler for HTTP GET requests matching the specified route pattern.
Syntax
Section titled “Syntax”template <typename THandler>void mapGet(std::string_view pattern, THandler&& handler);Parameters
Section titled “Parameters”| Name | Description |
|---|---|
pattern |
The route pattern to match (e.g. “/api/users”). |
handler |
The handler invoked when a request matches the route pattern. |
Exceptions
Section titled “Exceptions”| Exception | Condition |
|---|---|
std::logic_error |
Thrown if a route with the same HTTP method and route pattern has already been registered. |
Remarks
Section titled “Remarks”- The endpoint is registered immediately when this function is called.
- A corresponding
HEADendpoint is automatically available for every registeredGETendpoint. OPTIONSrequests are handled automatically by the framework.
Thread Safety
Section titled “Thread Safety”This function is not thread-safe. Concurrent route registration must be synchronized externally.
Example
Section titled “Example”app.mapGet("/", [] { return mach::ok();});See Also
Section titled “See Also”| 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. |