Skip to main content

Crate rainier_http

Crate rainier_http 

Source
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 exactly as $request->input('title') is in Laravel. 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 serde deserialiser that coerces strings into scalars.
cookie
Cookies — Cookie, SameSite and the Cookie: / 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, and IntoResponse for returning one from a handler.
upload
multipart/form-data parsing — UploadedFile and the file bag.

Macros§

static_name
Declare a StaticName marker type.

Structs§

HeaderMap
A specialized multimap for header names and values.
Method
The Request Method (VERB)
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
Uri
The URI component of a request.
Version
Represents a version of the HTTP spec.