Overview
mach::results
Description
Section titled “Description”Provides helper functions for creating common HTTP responses, such as ok(), created(), badRequest(), and notFound().
Headers
Section titled “Headers”Primary header:
#include <mach/results/Results.hpp>Convenience header:
#include <mach/mach.hpp>Syntax
Section titled “Syntax”namespace mach {
template <typename T> [[nodiscard]] Reply<T> ok(T value);
[[nodiscard]] Reply<std::string> ok(const char* value);
[[nodiscard]] Reply<> ok();
template <typename T> [[nodiscard]] Reply<T> created(T value);
[[nodiscard]] Reply<std::string> created(const char* value);
[[nodiscard]] Reply<> created();
[[nodiscard]] Reply<> noContent();
template <typename T> [[nodiscard]] Reply<T> badRequest(T value);
[[nodiscard]] Reply<std::string> badRequest(const char* value);
template <typename T = void> [[nodiscard]] Reply<T> badRequest();
template <typename T> [[nodiscard]] Reply<T> unauthorized(T value);
[[nodiscard]] Reply<std::string> unauthorized(const char* value);
template <typename T = void> [[nodiscard]] Reply<T> unauthorized();
template <typename T> [[nodiscard]] Reply<T> forbidden(T value);
[[nodiscard]] Reply<std::string> forbidden(const char* value);
template <typename T = void> [[nodiscard]] Reply<T> forbidden();
template <typename T> [[nodiscard]] Reply<T> notFound(T value);
[[nodiscard]] Reply<std::string> notFound(const char* value);
template <typename T = void> [[nodiscard]] Reply<T> notFound();
template <typename T> [[nodiscard]] Reply<T> conflict(T value);
[[nodiscard]] Reply<std::string> conflict(const char* value);
template <typename T = void> [[nodiscard]] Reply<T> conflict();}Functions
Section titled “Functions”| Name | Description |
|---|---|
ok |
Creates a 200 OK response. |
created |
Creates a 201 Created response. |
noContent |
Creates a 204 No Content response. |
badRequest |
Creates a 400 Bad Request response. |
unauthorized |
Creates a 401 Unauthorized response. |
forbidden |
Creates a 403 Forbidden response. |
notFound |
Creates a 404 Not Found response. |
conflict |
Creates a 409 Conflict response. |
Remarks
Section titled “Remarks”These functions are convenience wrappers for constructing Reply objects and can be used from Minimal API handlers. Controller actions may also use the inherited helper functions provided by ControllerBase.
Example
Section titled “Example”app.mapGet("/users/{id:int}", [] { return mach::ok(User{1, "Alice"});});
app.mapPost("/users", [] { return mach::badRequest("The request is invalid.");});See Also
Section titled “See Also”| Name | Description |
|---|---|
Reply |
Represents the result of an HTTP endpoint. |
Response |
Represents the HTTP response being built. |