To return a HTML response from a HTTP server in Rust, you can use the hyper
crate as follows:
main.rs747 chars24 lines
In this example, we bind a Server
to a socket address (localhost:8080
). The server's make_service_fn
function creates a new instance of a service on each incoming connection, and sets it up to serve this request. This service function (handle_request
) takes a request and returns a Result
with a Response
that contains the HTML content.
The tokio::main
macro is used here to initiate an asynchronous runtime and run the server.
gistlibby LogSnag