Setting up a basic HTTP server
Let's start our chapter by bringing the famous Hello World program into the 21st century by hosting it on a server. We are going to use the hyper
crate for this, which is a strongly typed wrapper around all things HTTP. In addition to being one of the fastest HTTP implementations in the world (https://www.techempower.com/benchmarks/#section=data-r15&hw=ph&test=plaintext), it is used by nearly all major high-level frameworks (https://github.com/flosse/rust-web-framework-comparison#high-level-frameworks), the only exception being the ones that reimplemented it all on the extremely basic stringly-typed TCP library that Rust provides under std::net::TcpStream
.
Getting ready
All hyper
recipes work with futures
, so you should read all of Chapter 8, Working with Futures, before continuing.
At the time of writing, hyper
has not yet upgraded to futures v0.2
(tracking issue: https://github.com/hyperium/hyper/issues/1448), so we going to use futures v0.1
. This should...