Skip to main content

IHttpRequest

Trait IHttpRequest 

Source
pub trait IHttpRequest: Send {
    // Required methods
    fn method(&self) -> &str;
    fn path(&self) -> &str;
    fn header(&self, name: &str) -> Option<&str>;
    fn query(&self) -> &HashMap<String, String>;
    fn route_params(&self) -> &HashMap<String, String>;
    fn route_params_mut(&mut self) -> &mut HashMap<String, String>;
    fn route_pattern(&self) -> Option<&str>;
    fn route_pattern_mut(&mut self) -> &mut Option<String>;
    fn body_bytes<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn body_text<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

HTTP request abstraction.

Analogous to ASP.NET Core’s HttpRequest.

Methods are non-generic to maintain dyn-compatibility. Use serde_json::from_slice on the raw body bytes for JSON deserialization.

Required Methods§

Source

fn method(&self) -> &str

Source

fn path(&self) -> &str

Source

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

Source

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

Source

fn route_params(&self) -> &HashMap<String, String>

Source

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

Source

fn route_pattern(&self) -> Option<&str>

The original route pattern that was matched (e.g., "/api/users/{id}"). Set by the router after successful route matching.

Source

fn route_pattern_mut(&mut self) -> &mut Option<String>

Source

fn body_bytes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the raw request body bytes.

Provided Methods§

Source

fn body_text<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Return the request body as a UTF-8 string.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§