Skip to content
Download

App

mach::App

Represents a configured Mach application.

Primary header:

#include <mach/App.hpp>

Convenience header:

#include <mach/mach.hpp>
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();
};
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.

This class is not thread-safe.

  • Owns the application’s runtime state.
  • Represents the root runtime object of a Mach application.
  • 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.
auto app = builder.build();
app.mapGet("/", [] {
return mach::ok("Hello, world!");
});
app.run();
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.