HTTP
HTTP is the request/response protocol of the web. In Rust you speak it with a client crate (reqwest) or a server crate (Axum, Actix) sitting on Tokio and a type that maps headers, method, path, and body.
Detailed Explanation
An HTTP request is a method, a target, headers, and an optional body. A response is a status, headers, and a body. Rust does not include a server in std. std::net::TcpListener gives you bytes. You do not want to parse HTTP/1.1 yourself. hyper is the common low-level library. Axum and Actix sit on top of it (or their own stack) and give you extractors, routing, and middleware.
On the client side, reqwest is the usual crate: reqwest::get(url).await?.text().await?. It handles TLS, redirects, and JSON if you enable features. A smaller crate (ureq) is blocking and fine for CLIs. Do not std::net::TcpStream plus write_all(b"GET /") except as an exercise.
Status codes are http::StatusCode in the shared http crate that almost everyone uses. Headers are case-insensitive maps. Bodies are bytes; serde_json turns them into structs. Timeouts belong at the client (reqwest::ClientBuilder::timeout) and at the server (a tower layer or a reverse proxy). Forgetting a timeout is how a handler waits forever on a peer.
HTTP is not encryption. HTTPS is HTTP over TLS. In production you terminate TLS at a proxy or you configure rustls on the server. Local http:// is fine. Shipping http:// for a login form is not.
When you reach for a server crate: you are writing an API. When you reach for reqwest: you are calling one. When you reach for hyper directly: you need a custom connection or you are writing a library the others sit on.
HTTP/2 and HTTP/3 change frames, not the request model your handler sees. Axum still gives you a method, a path, and a body. Do not invent a second HTTP stack for HTTP/2; hyper already speaks it when you enable the feature. What you must still handle is body size limits, header size limits, and slow-loris-style drips — usually at the proxy or a Tower limit layer.
Code Examples
use http::{Method, Request};
fn main() {
let req = Request::builder()
.method(Method::GET)
.uri("/health")
.body(())
.unwrap();
println!("{} {}", req.method(), req.uri()); // prints: GET /health
}Common Gotchas
There is no HTTP server in `std`
A `TcpListener` is not a web framework. Use Axum or Actix unless you are writing one.
A missing timeout is a hung task
Set client and server timeouts. `await` on a body without a limit can run until memory dies.
The `http` crate is the shared types
`StatusCode` and `HeaderMap` show up in Axum, hyper, and reqwest. Learn those types once.
HTTP is plaintext
Credentials need HTTPS. Do not log `Authorization` headers.