|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
HTTP server with URI handler registration and RAII lifecycle. More...
Classes | |
| struct | config |
| HTTP server configuration. More... | |
| class | error_category |
| Error category for HTTP server errors. More... | |
Public Types | |
| enum class | errc : esp_err_t { handlers_full = 0xb001 , handler_exists = 0xb002 , invalid_request = 0xb003 , result_truncated = 0xb004 , resp_header = 0xb005 , resp_send = 0xb006 , alloc_mem = 0xb007 , task = 0xb008 } |
| Error codes for HTTP server operations. More... | |
| using | handler_type = std::move_only_function< result< void >(request &) const > |
| Handler function type for URI handlers. | |
Public Member Functions | |
| server (config cfg) | |
| Creates and starts an HTTP server. | |
| virtual | ~server () |
| Stops the server and releases all resources. | |
| server (const server &)=delete | |
| server & | operator= (const server &)=delete |
| server (server &&) noexcept | |
| Move constructor. | |
| server & | operator= (server &&) noexcept |
| Move assignment. | |
| void | on (enum method m, std::string uri, handler_type handler) |
| Registers a URI handler for a specific HTTP method. | |
| void | on_any (std::string uri, handler_type handler) |
| Registers a URI handler that matches any HTTP method. | |
| void | on_get (std::string uri, handler_type handler) |
| Registers a GET handler. | |
| void | on_post (std::string uri, handler_type handler) |
| Registers a POST handler. | |
| void | on_put (std::string uri, handler_type handler) |
| Registers a PUT handler. | |
| void | on_patch (std::string uri, handler_type handler) |
| Registers a PATCH handler. | |
| void | on_delete (std::string uri, handler_type handler) |
| Registers a DELETE handler. | |
| void | on_head (std::string uri, handler_type handler) |
| Registers a HEAD handler. | |
| result< void > | try_on (enum method m, std::string uri, handler_type handler) |
| Registers a URI handler for a specific HTTP method. | |
| result< void > | try_on_any (std::string uri, handler_type handler) |
| Registers a URI handler that matches any HTTP method. | |
| result< void > | try_on_get (std::string uri, handler_type handler) |
| Registers a GET handler. | |
| result< void > | try_on_post (std::string uri, handler_type handler) |
| Registers a POST handler. | |
| result< void > | try_on_put (std::string uri, handler_type handler) |
| Registers a PUT handler. | |
| result< void > | try_on_patch (std::string uri, handler_type handler) |
| Registers a PATCH handler. | |
| result< void > | try_on_delete (std::string uri, handler_type handler) |
| Registers a DELETE handler. | |
| result< void > | try_on_head (std::string uri, handler_type handler) |
| Registers a HEAD handler. | |
| void | unregister_handler (enum method m, std::string_view uri) |
| Unregisters a URI handler. | |
| result< void > | try_unregister_handler (enum method m, std::string_view uri) |
| Unregisters a URI handler. | |
| void | close_session (int sockfd) |
| Closes a client session by socket file descriptor. | |
| result< void > | try_close_session (int sockfd) |
| Closes a client session by socket file descriptor. | |
| httpd_handle_t | idf_handle () const noexcept |
| Returns the underlying ESP-IDF HTTP server handle. | |
Static Public Member Functions | |
| static result< server > | make (config cfg) |
| Creates and starts an HTTP server. | |
HTTP server with URI handler registration and RAII lifecycle.
Manages an HTTP server instance. Register URI handlers as C++ callables, which are invoked when matching requests arrive. Supports standard HTTP methods and optional WebSocket endpoints.
Not thread-safe for handler registration — register all handlers before serving concurrent requests.
Definition at line 478 of file server.hpp.
Handler function type for URI handlers.
Definition at line 481 of file server.hpp.
|
strong |
Error codes for HTTP server operations.
Definition at line 486 of file server.hpp.
|
explicit |
Creates and starts an HTTP server.
| cfg | Server configuration. |
| std::system_error | on failure. |
|
virtual |
Stops the server and releases all resources.
|
noexcept |
Move constructor.
Transfers server ownership.
Closes a client session by socket file descriptor.
| sockfd | The socket file descriptor to close. |
| std::system_error | on failure. |
Definition at line 861 of file server.hpp.
References try_close_session(), and idfxx::unwrap().
|
inlinenoexcept |
Returns the underlying ESP-IDF HTTP server handle.
Definition at line 880 of file server.hpp.
Creates and starts an HTTP server.
| cfg | Server configuration. |
|
inline |
Registers a URI handler for a specific HTTP method.
| m | The HTTP method to handle. |
| uri | The URI pattern to match. |
| handler | The handler function. |
| std::system_error | on failure. |
Definition at line 619 of file server.hpp.
References try_on(), and idfxx::unwrap().
|
inline |
Registers a URI handler that matches any HTTP method.
| uri | The URI pattern to match. |
| handler | The handler function. |
| std::system_error | on failure. |
Definition at line 631 of file server.hpp.
References try_on_any(), and idfxx::unwrap().
|
inline |
Registers a DELETE handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
| std::system_error | on failure. |
Definition at line 681 of file server.hpp.
References try_on_delete(), and idfxx::unwrap().
|
inline |
Registers a GET handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
| std::system_error | on failure. |
Definition at line 641 of file server.hpp.
References try_on_get(), and idfxx::unwrap().
|
inline |
Registers a HEAD handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
| std::system_error | on failure. |
Definition at line 691 of file server.hpp.
References try_on_head(), and idfxx::unwrap().
|
inline |
Registers a PATCH handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
| std::system_error | on failure. |
Definition at line 671 of file server.hpp.
References try_on_patch(), and idfxx::unwrap().
|
inline |
Registers a POST handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
| std::system_error | on failure. |
Definition at line 651 of file server.hpp.
References try_on_post(), and idfxx::unwrap().
|
inline |
Registers a PUT handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
| std::system_error | on failure. |
Definition at line 661 of file server.hpp.
References try_on_put(), and idfxx::unwrap().
Move assignment.
Transfers server ownership.
Closes a client session by socket file descriptor.
| sockfd | The socket file descriptor to close. |
Referenced by close_session().
| result< void > idfxx::http::server::try_on | ( | enum method | m, |
| std::string | uri, | ||
| handler_type | handler | ||
| ) |
Registers a URI handler for a specific HTTP method.
| m | The HTTP method to handle. |
| uri | The URI pattern to match. |
| handler | The handler function. |
Referenced by on(), try_on_delete(), try_on_get(), try_on_head(), try_on_patch(), try_on_post(), and try_on_put().
| result< void > idfxx::http::server::try_on_any | ( | std::string | uri, |
| handler_type | handler | ||
| ) |
Registers a URI handler that matches any HTTP method.
| uri | The URI pattern to match. |
| handler | The handler function. |
Referenced by on_any().
|
inline |
Registers a DELETE handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
Definition at line 764 of file server.hpp.
References idfxx::http::delete_, and try_on().
Referenced by on_delete().
|
inline |
Registers a GET handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
Definition at line 720 of file server.hpp.
References idfxx::http::get, and try_on().
Referenced by on_get().
|
inline |
Registers a HEAD handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
Definition at line 775 of file server.hpp.
References idfxx::http::head, and try_on().
Referenced by on_head().
|
inline |
Registers a PATCH handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
Definition at line 753 of file server.hpp.
References idfxx::http::patch, and try_on().
Referenced by on_patch().
|
inline |
Registers a POST handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
Definition at line 731 of file server.hpp.
References idfxx::http::post, and try_on().
Referenced by on_post().
|
inline |
Registers a PUT handler.
| uri | The URI pattern to match. |
| handler | The handler function. |
Definition at line 742 of file server.hpp.
References idfxx::http::put, and try_on().
Referenced by on_put().
Unregisters a URI handler.
| m | The HTTP method of the handler to remove. |
| uri | The URI of the handler to remove. |
Referenced by unregister_handler().
Unregisters a URI handler.
| m | The HTTP method of the handler to remove. |
| uri | The URI of the handler to remove. |
| std::system_error | on failure. |
Definition at line 792 of file server.hpp.
References try_unregister_handler(), and idfxx::unwrap().