Module http

Shared type definitions for the HTTP protocol.


http provides the common vocabulary types for HTTP used across the Rust ecosystem. hyper, axum, reqwest, and other HTTP libraries all build on these types, making them interoperable.

This crate defines types only, with no I/O or protocol logic.

Examples

Building a request and inspecting its parts:

use http::{Request, Method, StatusCode, Response};

let req = Request::builder()
    .method(Method::GET)
    .uri("https://example.com/path?q=1")
    .header("Accept", "application/json")
    .body(())
    .unwrap();

assert_eq!(req.method(), Method::GET);
assert_eq!(req.uri().path(), "/path");
assert_eq!(req.uri().query(), Some("q=1"));
assert_eq!(
    req.headers()["Accept"],
    "application/json",
);

let resp = Response::builder()
    .status(StatusCode::NOT_FOUND)
    .header("Content-Type", "text/plain")
    .body(())
    .unwrap();

assert_eq!(resp.status(), StatusCode::NOT_FOUND);
assert_eq!(resp.status().as_u16(), 404);

Modules