App
mach::App
Description
Section titled “Description”Represents a configured Mach application.
Headers
Section titled “Headers”Primary header:
#include <mach/App.hpp>Convenience header:
#include <mach/mach.hpp>Syntax
Section titled “Syntax”class App {
public: ~App(); App(App&&) noexcept;
[[nodiscard]] std::string host() const noexcept;
[[nodiscard]] std::uint16_t port() const noexcept;
[[nodiscard]] std::size_t threadCount() const noexcept;
template <typename THandler> void mapGet(std::string_view pattern, THandler&& handler);
template <typename THandler> void mapPost(std::string_view pattern, THandler&& handler);
template <typename THandler> void mapPut(std::string_view pattern, THandler&& handler);
template <typename THandler> void mapPatch(std::string_view pattern, THandler&& handler);
template <typename THandler> void mapDelete(std::string_view pattern, THandler&& handler);
template <typename THandler> void mapHead(std::string_view pattern, THandler&& handler);
template <typename THandler> void addRoute(http::Method method, std::string_view pattern, THandler&& handler);
[[nodiscard]] int run();
void stop();};Member Functions
Section titled “Member Functions”| Name | Description |
|---|---|
host |
Returns the application host. |
port |
Returns the application port. |
threadCount |
Returns the configured worker thread count. |
mapGet |
Registers a GET request handler. |
mapPost |
Registers a POST request handler. |
mapPut |
Registers a PUT request handler. |
mapPatch |
Registers a PATCH request handler. |
mapDelete |
Registers a DELETE request handler. |
mapHead |
Registers a HEAD request handler. |
run |
Starts the application. |
stop |
Stops the application. |
Thread Safety
Section titled “Thread Safety”This class is not thread-safe.
Ownership
Section titled “Ownership”- Owns the application’s runtime state.
- Represents the root runtime object of a Mach application.
Remarks
Section titled “Remarks”- An application instance may be started only once.
- Calling
run()blocks until the application shuts down. - Use
stop()to request a graceful shutdown from another thread.
Example
Section titled “Example”auto app = builder.build();
app.mapGet("/", [] { return mach::ok("Hello, world!");});
app.run();See Also
Section titled “See Also”| Name | Description |
|---|---|
AppBuilder |
Builds and configures a Mach application. |
Context |
Provides access to the current HTTP request and response. |
ControllerBase |
Base class for defining controllers. |