Skip to main content

rainier_http/
lib.rs

1//! # rainier-http
2//!
3//! The HTTP message layer: [`Request`], [`Response`], [`Body`], [`Cookie`],
4//! uploads, and the [`FromRequest`] extractors controller actions are written
5//! against.
6//!
7//! It knows nothing about routing, middleware or the server — those are layered
8//! on top. That is what lets a test drive a controller with a hand-built
9//! [`Request`] and assert on the [`Response`], with no runtime and no socket:
10//!
11//! ```
12//! use rainier_http::{IntoResponse, Request, Response};
13//! use http::{Method, StatusCode};
14//!
15//! async fn show(request: &Request) -> Response {
16//!     match request.input("id") {
17//!         Some(id) => Response::json(&serde_json::json!({ "id": id })),
18//!         None => Response::new(StatusCode::BAD_REQUEST),
19//!     }
20//! }
21//!
22//! # #[tokio::main] async fn main() {
23//! let request = Request::builder().method(Method::GET).uri("/posts?id=7").build();
24//! assert_eq!(show(&request).await.status(), StatusCode::OK);
25//! # }
26//! ```
27//!
28//! ## The buffered-request decision
29//!
30//! Request bodies arrive fully buffered, so `request.input("title")` is a plain
31//! synchronous call exactly as `$request->input('title')` is in Laravel.
32//! Response bodies may stream. See [`body`] for why the asymmetry is
33//! deliberate rather than an omission.
34
35#![deny(missing_docs)]
36#![deny(rustdoc::broken_intra_doc_links)]
37
38pub mod body;
39pub mod coerce;
40pub mod cookie;
41pub mod extract;
42pub mod input;
43pub mod request;
44pub mod response;
45pub mod upload;
46
47pub use body::Body;
48pub use cookie::{Cookie, SameSite};
49pub use extract::FromRequest;
50pub use request::{ClientIp, Request, RequestBuilder};
51pub use response::{Html, IntoResponse, Json, Redirect, RenderedError, Response};
52pub use upload::{Multipart, UploadedFile};
53
54// Re-exported so downstream crates and applications reference one `http`
55// version rather than accidentally depending on a second copy.
56pub use http;
57pub use http::{HeaderMap, Method, StatusCode, Uri, Version};