33 boost::asio::io_context io_context;
39 response.result(boost::beast::http::status::ok);
40 response.set(boost::beast::http::field::content_type,
"text/plain");
41 response.body() =
"Hello, World!";
42 response.prepare_payload();
48 response.result(boost::beast::http::status::ok);
49 response.set(boost::beast::http::field::content_type,
"text/plain");
50 response.body() =
"Shutting down server...";
51 response.prepare_payload();
53 boost::asio::post(io_context, [&server] {
60 const auto result = server.
start(
"127.0.0.1", 8080);
61 if (result.has_error()) {
62 RAV_LOG_ERROR(
"Error starting server: {}", result.error().message());
A high-level wrapper around boost::beast for creating an HTTP server.
boost::beast::http::response< boost::beast::http::string_body > Response
boost::system::result< void > start(std::string_view bind_address, uint16_t port)
Starts the server on the given host and port.
void stop()
Stops the server and closes all client sessions.
std::string get_address_string() const
boost::beast::http::request< boost::beast::http::string_body > Request
void get(const std::string_view pattern, Handler handler)
Adds a handler for GET requests to the given pattern.
Contains parameters extracted from a path with convenience functions to convert to integers.
#define RAV_LOG_ERROR(...)
#define RAV_LOG_INFO(...)
void set_log_level_from_env(const char *env_var="RAV_LOG_LEVEL")
Tries to find given environment variable and set the log level accordingly.