Reply
mach::Reply
Description
Section titled “Description”Represents the result returned from a route handler or controller action.
Headers
Section titled “Headers”Primary header:
#include <mach/Reply.hpp>Convenience header:
#include <mach/mach.hpp>Syntax
Section titled “Syntax”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;};Template Parameters
Section titled “Template Parameters”| Type | Description |
|---|---|
T |
The type of the response body. |
Constructors
Section titled “Constructors”| Name | Description |
|---|---|
Reply |
Creates a reply object. |
Member Functions
Section titled “Member Functions”| 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. |
Member Types
Section titled “Member Types”| Name | Description |
|---|---|
ValueType |
The response body type. |
Thread Safety
Section titled “Thread Safety”Thread-safe. All member functions may be called concurrently from multiple threads.
Remarks
Section titled “Remarks”- Controller actions return
Replyobjects to define the HTTP response. - Minimal API handlers may return either a
Replyobject orvoid.
Example
Section titled “Example”app.mapGet("/users/{id:int}", [](mach::Context& context) { auto id = context.routeParam<int>("id");
return mach::ok(User{ .id = id, .name = "John" });});See Also
Section titled “See Also”| Name | Description |
|---|---|
Results |
Creates HTTP responses from route handlers. |