Skip to content
Download

Reply

mach::Reply

Represents the result returned from a route handler or controller action.

Primary header:

#include <mach/Reply.hpp>

Convenience header:

#include <mach/mach.hpp>
template <typename T = void>
class Reply {
public:
explicit Reply(http::StatusCode statusCode);
Reply(http::StatusCode statusCode, T value);
[[nodiscard]] http::StatusCode statusCode() const noexcept;
[[nodiscard]] const T& value() const;
[[nodiscard]] bool hasValue() const noexcept;
};
Type Description
T The type of the response body.
Name Description
Reply Creates a reply object.
Name Description
statusCode Returns the reply’s HTTP status code.
value The response body, if present.
hasValue Indicates whether the reply contains a response body.
Name Description
ValueType The response body type.

Thread-safe. All member functions may be called concurrently from multiple threads.

  • Controller actions return Reply objects to define the HTTP response.
  • Minimal API handlers may return either a Reply object or void.
app.mapGet("/users/{id:int}", [](mach::Context& context) {
auto id = context.routeParam<int>("id");
return mach::ok(User{
.id = id,
.name = "John"
});
});
Name Description
Results Creates HTTP responses from route handlers.