Request

Struct Request 

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

Represents an incoming HTTP request.

Provides high-level access to request data without exposing unsafe code. Data is lazily loaded from the host on first access.

Implementations§

Source§

impl Request

Source

pub fn method(&mut self) -> Method

Returns the HTTP method as an enum.

Source

pub fn method_str(&mut self) -> String

Returns the HTTP method as a string.

Source

pub fn path(&mut self) -> &str

Returns the request path (e.g., “/api/users/123”).

Source

pub fn path_segments(&mut self) -> &[String]

Returns the path split into segments. Example: “/api/users/123” -> [“api”, “users”, “123”]

Source

pub fn path_segment(&mut self, index: usize) -> Option<&str>

Returns a specific path segment by index. Example: for “/api/users/123”, segment(1) returns Some(“users”)

Source

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

Returns all query parameters as a map. If a key appears multiple times, only the last value is kept.

Source

pub fn query_all(&mut self) -> &[(String, String)]

Returns all query parameters as a list of key-value pairs. Preserves duplicate keys.

Source

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

Gets a query parameter by name.

Source

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

Returns all headers as a map. Header names are lowercase.

Source

pub fn headers_all(&mut self) -> &[(String, String)]

Returns all headers as a list of key-value pairs.

Source

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

Gets a header by name (case-insensitive).

Source

pub fn content_type(&mut self) -> Option<&str>

Returns the Content-Type header value.

Source

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

Returns all cookies as a map.

Source

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

Gets a cookie by name.

Source

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

Returns the request body as bytes.

Source

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

Returns the request body as a string. Returns an error if the body is not valid UTF-8.

Source

pub fn body_json<T: DeserializeOwned>(&mut self) -> Result<T, Error>

Parses the request body as JSON.

Trait Implementations§

Source§

impl Default for Request

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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.