pub struct Request { /* private fields */ }Expand description
A request with parsed path parameters and query string.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(
inner: Request<Incoming>,
path_params: HashMap<String, String>,
) -> Self
pub fn new( inner: Request<Incoming>, path_params: HashMap<String, String>, ) -> Self
Create a new Request wrapping a hyper request.
Sourcepub fn param(&self, name: &str) -> Option<&str>
pub fn param(&self, name: &str) -> Option<&str>
Get a path parameter by name (e.g. from /users/:id).
Sourcepub fn query_params(&self) -> HashMap<String, String>
pub fn query_params(&self) -> HashMap<String, String>
Parse query parameters from the URI.
Sourcepub fn into_inner(self) -> Request<Incoming>
pub fn into_inner(self) -> Request<Incoming>
Consume the request and return the inner hyper request.
Sourcepub async fn body_bytes(self) -> Result<Bytes, OxiHttpError>
pub async fn body_bytes(self) -> Result<Bytes, OxiHttpError>
Consume the body and return raw bytes.
Sourcepub async fn body_text(self) -> Result<String, OxiHttpError>
pub async fn body_text(self) -> Result<String, OxiHttpError>
Consume the body and return it as a UTF-8 string.
Sourcepub async fn body_json<T: DeserializeOwned>(self) -> Result<T, OxiHttpError>
pub async fn body_json<T: DeserializeOwned>(self) -> Result<T, OxiHttpError>
Consume the body and deserialize from JSON.
Sourcepub fn state<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>
pub fn state<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>
Retrieve the shared application state of type T.
Returns Some(Arc<T>) when Router::with_state::<T>() was used to
register a value of type T before starting the server. Returns None
when no state of that type was injected.
Sourcepub fn extension<T: Clone + Send + Sync + 'static>(&self) -> Option<T>
pub fn extension<T: Clone + Send + Sync + 'static>(&self) -> Option<T>
Retrieve a per-request extension of type T.
Handlers and middleware can store arbitrary values in request extensions
via req.extensions_mut().insert(value). This accessor clones the
stored value and returns it.
Sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Access the raw request extensions map (read-only).
Sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Access the raw request extensions map (mutable).
Useful in middleware or handlers that need to attach data for downstream consumers.
Sourcepub fn parts(&self) -> RequestParts<'_>
pub fn parts(&self) -> RequestParts<'_>
Borrow the non-body request parts as a RequestParts.
Used internally by Request::extract and available for manual
extraction via FromRequestParts.
Sourcepub fn extract<T: FromRequestParts>(&self) -> Result<T, T::Rejection>
pub fn extract<T: FromRequestParts>(&self) -> Result<T, T::Rejection>
Extract a value implementing FromRequestParts
from this request.
§Errors
Returns the extractor’s Rejection type (which converts to OxiHttpError)
when extraction fails.
Sourcepub fn negotiate(&self, supported: &[ContentType]) -> Option<ContentType>
pub fn negotiate(&self, supported: &[ContentType]) -> Option<ContentType>
Negotiate the best ContentType from the
request’s Accept header and the supplied list of supported types.
Returns None when no supported type satisfies the client’s Accept
header. Falls back to */* matching when the header is absent.