pub fn serve<H>(addr: impl ToSocketAddrs, handler: H) -> Result<()>Available on crate feature
std only.Expand description
Binds addr and serves handler with the default ServerConfig
until the process ends: the shortest way to run a server. Use
Server for a shutdown handle, settings, or an upgrade hook.
§Errors
The bind error, or a persistent accept failure (see Server::serve).
§Examples
Not run: it serves until the process ends.
use http_net::{blocking, Response};
blocking::serve("127.0.0.1:8080", |req, _body| Response::text(200, req.path()))?;