Skip to main content

Request

Struct Request 

Source
pub struct Request { /* private fields */ }
Expand description

A request with parsed path parameters and query string.

Implementations§

Source§

impl Request

Source

pub fn new( inner: Request<Incoming>, path_params: HashMap<String, String>, ) -> Self

Create a new Request wrapping a hyper request.

Source

pub fn method(&self) -> &Method

The HTTP method.

Source

pub fn uri(&self) -> &Uri

The request URI.

Source

pub fn headers(&self) -> &HeaderMap

The request headers.

Source

pub fn path(&self) -> &str

The path portion of the URI.

Source

pub fn param(&self, name: &str) -> Option<&str>

Get a path parameter by name (e.g. from /users/:id).

Source

pub fn params(&self) -> &HashMap<String, String>

Get all path parameters.

Source

pub fn query_params(&self) -> HashMap<String, String>

Parse query parameters from the URI.

Source

pub fn query(&self, name: &str) -> Option<String>

Get a single query parameter by name.

Source

pub fn into_inner(self) -> Request<Incoming>

Consume the request and return the inner hyper request.

Source

pub async fn body_bytes(self) -> Result<Bytes, OxiHttpError>

Consume the body and return raw bytes.

Source

pub async fn body_text(self) -> Result<String, OxiHttpError>

Consume the body and return it as a UTF-8 string.

Source

pub async fn body_json<T: DeserializeOwned>(self) -> Result<T, OxiHttpError>

Consume the body and deserialize from JSON.

Source

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.

Source

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.

Source

pub fn extensions(&self) -> &Extensions

Access the raw request extensions map (read-only).

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more