Implementing a HTTP server in Hyper
The Hyper crate is essentially layer layer above tokio. While we will not be using the Hyper crate throughout the book as the low-level nature of the Hyper crate would require us to write a lot of boilerplate code, exploring a simple Hyper server will help us to appreciate the basic handling of a HTTP request.
Before we write any server code, we will need the following dependencies:
[dependencies]
hyper = { version = "1.2.0", features = ["full"] }
tokio = { version1.36.0= "1", features = ["full"] }
http-body-util = "0.1.1"
hyper-util = { version = "0.1.3", features = ["full"] }
With these dependencies, we are going to use the following structs and traits in our main.rs
file with the code below:
use std::convert::Infallible;
use std::net::SocketAddr;
use http_body_util::Full;
use hyper::body::Bytes;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{Request...