expression

Response builder: status, headers and body

Represent a server response in memory. A status code, headers and body have distinct roles. This example creates a successful text response but does not transmit it. External crate example; constructs data in memory, does not send requests. Expected stdout (not executed): 200 ready Common mistake: Treating a constructed Response as proof of a successful network exchange.

Formal Syntax & Structure

rust syntaxrust
http::Response::builder().status(code).header(name, value).body(data)

Working Example

Example Snippetrust
fn main() {    use http::{Response, StatusCode};    let res = Response::builder().status(StatusCode::OK).header("content-type", "text/plain").body("ready").unwrap();    println!("{} {}", res.status().as_u16(), res.body());}
Rust Reference