Struct Request

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

HTTP Request wrapper that provides convenient access to request data

Implementations§

Source§

impl Request

Source

pub fn new() -> Self

Create a simple empty request (for internal use)

Source

pub async fn from_hyper( parts: Parts, body: Incoming, ) -> Result<Self, Box<dyn Error + Send + Sync>>

Create a new Request from hyper’s request parts and body

Source

pub fn method(&self) -> &Method

Get the HTTP method

Source

pub fn uri(&self) -> &Uri

Get the URI

Source

pub fn path(&self) -> &str

Get the path from the URI

Source

pub fn version(&self) -> Version

Get the HTTP version

Source

pub fn headers(&self) -> &HeaderMap

Get the headers

Source

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

Get a specific header value

Source

pub fn body(&self) -> &[u8]

Get the request body as bytes

Source

pub fn body_string(&self) -> Result<String, FromUtf8Error>

Get the request body as a string

Source

pub async fn json<T>(&self) -> Result<T, Error>

Parse the request body as JSON (requires “json” feature)

Source

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

Get a path parameter by name

Source

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

Get all path parameters

Source

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

Get all path parameters (for extractors)

Source

pub fn extensions(&self) -> &HashMap<TypeId, Box<dyn Any + Send + Sync>>

Get a reference to the request extensions

Source

pub fn extensions_mut( &mut self, ) -> &mut HashMap<TypeId, Box<dyn Any + Send + Sync>>

Get a mutable reference to the request extensions

Source

pub fn insert_extension<T: Send + Sync + 'static>(&mut self, value: T)

Insert a value into the request extensions

Source

pub fn get_extension<T: Send + Sync + 'static>(&self) -> Option<&T>

Get a value from the request extensions

Source

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

Get a query parameter by name

Source

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

Get all query parameters

Source

pub fn query_string(&self) -> Option<&str>

Get the raw query string

Source

pub fn body_bytes(&self) -> &[u8]

Get the request body as bytes (for extractors)

Source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Get mutable access to headers (for extractors)

Trait Implementations§

Source§

impl Debug for Request

Source§

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

Formats the value using the given formatter. Read more
Source§

impl RequestDatabaseExt for Request

Source§

fn db_pool(&self) -> Option<()>

Source§

impl RequestStateExt for Request

Implementation of RequestStateExt for Request

Source§

fn get_state(&self, type_id: TypeId) -> Option<&Arc<dyn Any + Send + Sync>>

Get state by TypeId
Source§

fn set_state_map(&mut self, state_map: StateMap)

Set the state map for this request
Source§

fn state_map(&self) -> Option<&StateMap>

Get a reference to the state map

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