Module esp_idf_svc::http::server
source · Expand description
HTTP server
Provides an HTTP(S) server in EspHttpServer
, plus all related structs.
Typical usage of EspHttpServer
involves creating a function (or closure)
for every URI+method that the server is meant to handle. A minimal server that
only handles HTTP GET requests to index.html
looks like this:
use esp_idf_svc::http::server::{Configuration, EspHttpServer};
let mut server = EspHttpServer::new(&Configuration::default())?;
server.fn_handler("/index.html", Method::Get, |request| {
request
.into_ok_response()?
.write_all(b"<html><body>Hello world!</body></html>")
})?;
Note that the server is automatically started when instantiated, and stopped
when dropped. If you want to keep the server running indefinitely then
make sure it’s not dropped - you may add an infinite loop after the server
is created, use core::mem::forget
, or keep around a reference to it somehow.
You can find an example of handling GET/POST requests at json_post_handler.rs
.
You can find an example of HTTP+Websockets at examples/ws_guessing_game.js
.
By default, the ESP-IDF library allocates 512 bytes for reading and parsing
HTTP headers, but desktop web browsers might send headers longer than that.
If this becomes a problem, add CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
to your
sdkconfig.defaults
file.
Re-exports§
pub use super::*;
Modules§
Structs§
Traits§
Functions§
- Wraps the given function into an
FnHandler
.