A high-level wrapper around boost::beast for creating an HTTP server.
More...
#include <http_server.hpp>
|
| | HttpServer (boost::asio::io_context &io_context) |
| | Constructs a new HttpServer using the given io_context.
|
| | ~HttpServer () |
| 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.
|
| boost::asio::ip::tcp::endpoint | get_local_endpoint () const |
| std::string | get_address_string () const |
| size_t | get_client_count () const |
| void | get (const std::string_view pattern, Handler handler) |
| | Adds a handler for GET requests to the given pattern.
|
| void | post (const std::string_view pattern, Handler handler) |
| | Adds a handler for POST requests to the given pattern.
|
| void | options (const std::string_view pattern, Handler handler) |
| | Adds a handler for OPTIONS requests to the given pattern.
|
| void | patch (const std::string_view pattern, Handler handler) |
| | Adds a handler for PATCH requests to the given pattern.
|
|
| static constexpr auto | k_timeout_seconds = 5 |
| | The time to wait for a request before closing the connection.
|
A high-level wrapper around boost::beast for creating an HTTP server.
Definition at line 45 of file http_server.hpp.
◆ Handler
◆ Request
◆ Response
◆ HttpServer()
| rav::HttpServer::HttpServer |
( |
boost::asio::io_context & | io_context | ) |
|
|
explicit |
Constructs a new HttpServer using the given io_context.
The io_context must be single threaded.
- Parameters
-
| io_context | The io_context to use for the server. |
◆ ~HttpServer()
| rav::HttpServer::~HttpServer |
( |
| ) |
|
◆ get()
| void rav::HttpServer::get |
( |
const std::string_view | pattern, |
|
|
Handler | handler ) |
|
inline |
Adds a handler for GET requests to the given pattern.
- Parameters
-
| pattern | The pattern to match against the request path. |
| handler | The handler to call when a request matches the pattern. |
Definition at line 96 of file http_server.hpp.
◆ get_address_string()
| std::string rav::HttpServer::get_address_string |
( |
| ) |
const |
|
nodiscard |
- Returns
- The address string of the server in the format "address:port".
◆ get_client_count()
| size_t rav::HttpServer::get_client_count |
( |
| ) |
const |
|
nodiscard |
- Returns
- The number of active client sessions.
◆ get_local_endpoint()
| boost::asio::ip::tcp::endpoint rav::HttpServer::get_local_endpoint |
( |
| ) |
const |
|
nodiscard |
- Returns
- The local (listening) endpoint of the server.
◆ options()
| void rav::HttpServer::options |
( |
const std::string_view | pattern, |
|
|
Handler | handler ) |
|
inline |
Adds a handler for OPTIONS requests to the given pattern.
- Parameters
-
| pattern | The pattern to match against the request path. |
| handler | The handler to call when a request matches the pattern. |
Definition at line 114 of file http_server.hpp.
◆ patch()
| void rav::HttpServer::patch |
( |
const std::string_view | pattern, |
|
|
Handler | handler ) |
|
inline |
Adds a handler for PATCH requests to the given pattern.
- Parameters
-
| pattern | The pattern to match against the request path. |
| handler | The handler to call when a request matches the pattern. |
Definition at line 123 of file http_server.hpp.
◆ post()
| void rav::HttpServer::post |
( |
const std::string_view | pattern, |
|
|
Handler | handler ) |
|
inline |
Adds a handler for POST requests to the given pattern.
- Parameters
-
| pattern | The pattern to match against the request path. |
| handler | The handler to call when a request matches the pattern. |
Definition at line 105 of file http_server.hpp.
◆ start()
| boost::system::result< void > rav::HttpServer::start |
( |
std::string_view | bind_address, |
|
|
uint16_t | port ) |
Starts the server on the given host and port.
- Parameters
-
| bind_address | The address to bind to. |
| port | The port to bind to. |
- Returns
- An error code if the server fails to start, or an empty result if it succeeds.
◆ stop()
| void rav::HttpServer::stop |
( |
| ) |
|
Stops the server and closes all client sessions.
◆ k_timeout_seconds
| auto rav::HttpServer::k_timeout_seconds = 5 |
|
staticconstexpr |
The time to wait for a request before closing the connection.
Definition at line 52 of file http_server.hpp.
The documentation for this class was generated from the following file: