Expand description
§rainier-http
The HTTP message layer: Request, Response, Body, Cookie,
uploads, and the FromRequest extractors controller actions are written
against.
It knows nothing about routing, middleware or the server — those are layered
on top. That is what lets a test drive a controller with a hand-built
Request and assert on the Response, with no runtime and no socket:
use rainier_http::{IntoResponse, Request, Response};
use http::{Method, StatusCode};
async fn show(request: &Request) -> Response {
match request.input("id") {
Some(id) => Response::json(&serde_json::json!({ "id": id })),
None => Response::new(StatusCode::BAD_REQUEST),
}
}
let request = Request::builder().method(Method::GET).uri("/posts?id=7").build();
assert_eq!(show(&request).await.status(), StatusCode::OK);§The buffered-request decision
Request bodies arrive fully buffered, so request.input("title") is a plain
synchronous call.
Response bodies may stream. See body for why the asymmetry is
deliberate rather than an omission.
Re-exports§
pub use body::Body;pub use cookie::Cookie;pub use cookie::SameSite;pub use extract::FromRequest;pub use request::ClientIp;pub use request::Request;pub use request::RequestBuilder;pub use response::Html;pub use response::IntoResponse;pub use response::Json;pub use response::Redirect;pub use response::RenderedError;pub use response::Response;pub use upload::Multipart;pub use upload::UploadedFile;pub use http;
Modules§
- body
- Response bodies —
Body. - coerce
- A
serdedeserialiser that coerces strings into scalars. - cookie
- Cookies —
Cookie,SameSiteand theCookie:/Set-Cookie:encodings. - extract
FromRequest— typed extractors for controller actions.- input
- Turning query strings and form bodies into a uniform JSON tree.
- request
- The incoming
Request. - response
- The outgoing
Response, andIntoResponsefor returning one from a handler. - upload
multipart/form-dataparsing —UploadedFileand the file bag.
Macros§
- static_
name - Declare a
StaticNamemarker type.