An HTTP web framework and server for Rust supporting HTTP/1.1, HTTP/2, and HTTP/3. No third-party HTTP dependencies — parsing, routing, middleware, auth, WebSocket, SSE, caching, and tracing are all built in.
usecrate::app::App;usecrate::core::New;usecrate::response::STATUS_CODE_REASON_PHRASE;usecrate::test_client::TestClient;fnclient()->TestClient<App>{TestClient::new(App::new())}#[test]fnget_healthz_returns_200(){let res =client().get("/healthz").send();assert_eq!(*STATUS_CODE_REASON_PHRASE.n200_ok.status_code, res.status());assert!(res.is_success());}#[test]fnget_metrics_returns_200(){let res =client().get("/metrics").send();assert_eq!(*STATUS_CODE_REASON_PHRASE.n200_ok.status_code, res.status());}#[test]fnget_unknown_path_returns_404(){let res =client().get("/does-not-exist-xyzzy").send();assert_eq!(*STATUS_CODE_REASON_PHRASE.n404_not_found.status_code, res.status());}#[test]fnbody_text_is_accessible(){let res =client().get("/healthz").send();assert_eq!("OK", res.body_text());}#[test]fnheader_is_accessible_case_insensitive(){let res =client().get("/healthz").send();assert!(res.header("content-type").is_some());assert!(res.header("Content-Type").is_some());}#[test]fnrequest_header_is_forwarded(){let res =client().get("/healthz").header("Accept","text/plain").send();assert!(res.is_success());}#[test]fnpost_with_body_text(){let res =client().post("/healthz").body_text("hello").send();// /healthz only handles GET; POST falls through to 404
assert_eq!(*STATUS_CODE_REASON_PHRASE.n404_not_found.status_code, res.status());}#[test]fnis_success_false_for_4xx(){let res =client().get("/does-not-exist-xyzzy").send();assert!(!res.is_success());}#[test]fnbody_bytes_matches_body_text(){let res =client().get("/healthz").send();assert_eq!(res.body_text().as_bytes(), res.body_bytes());}