pub struct Request {
pub method: ElifMethod,
pub uri: Uri,
pub headers: ElifHeaderMap,
pub path_params: HashMap<String, String>,
pub query_params: HashMap<String, String>,
pub extensions: HashMap<TypeId, Box<dyn Any + Sync + Send>>,
/* private fields */
}Expand description
Request abstraction that wraps Axum’s request types with additional parsing and extraction capabilities
Fields§
§method: ElifMethod§uri: Uri§headers: ElifHeaderMap§path_params: HashMap<String, String>§query_params: HashMap<String, String>§extensions: HashMap<TypeId, Box<dyn Any + Sync + Send>>Implementations§
Source§impl ElifRequest
impl ElifRequest
Sourcepub fn input<T>(&self, key: &str, default: T) -> T
pub fn input<T>(&self, key: &str, default: T) -> T
Simple input extraction with default value
Searches query parameters first, then path parameters. Returns the default value if the parameter is missing or can’t be parsed.
Simple equivalent: $request->input('page', 1)
Sourcepub fn input_optional<T>(&self, key: &str) -> Option<T>
pub fn input_optional<T>(&self, key: &str) -> Option<T>
Simple input extraction that returns Option
Simple equivalent: $request->input('search')
Sourcepub fn string(&self, key: &str, default: &str) -> String
pub fn string(&self, key: &str, default: &str) -> String
Extract a string input with default
Simple equivalent: $request->input('name', 'default')
Sourcepub fn string_optional(&self, key: &str) -> Option<String>
pub fn string_optional(&self, key: &str) -> Option<String>
Extract an optional string input
Simple equivalent: $request->input('search')
Sourcepub fn integer(&self, key: &str, default: i64) -> i64
pub fn integer(&self, key: &str, default: i64) -> i64
Extract an integer input with default
Simple equivalent: $request->input('page', 1)
Sourcepub fn integer_optional(&self, key: &str) -> Option<i64>
pub fn integer_optional(&self, key: &str) -> Option<i64>
Extract an optional integer input
Simple equivalent: $request->input('limit')
Sourcepub fn boolean(&self, key: &str, default: bool) -> bool
pub fn boolean(&self, key: &str, default: bool) -> bool
Extract a boolean input with default
Recognizes: “true”, “1”, “on”, “yes” as true (case-insensitive)
Simple equivalent: $request->boolean('active', false)
Sourcepub fn inputs(&self, keys: &[&str]) -> HashMap<String, String>
pub fn inputs(&self, keys: &[&str]) -> HashMap<String, String>
Extract multiple inputs at once as a HashMap
Simple equivalent: $request->only(['name', 'email', 'age'])
Sourcepub fn all_query(&self) -> HashMap<String, String>
pub fn all_query(&self) -> HashMap<String, String>
Extract all query parameters as HashMap
Simple equivalent: $request->query()
Sourcepub fn has(&self, key: &str) -> bool
pub fn has(&self, key: &str) -> bool
Check if a parameter exists (in query or path)
Simple equivalent: $request->has('search')
Sourcepub fn filled(&self, key: &str) -> bool
pub fn filled(&self, key: &str) -> bool
Check if a parameter exists and is not empty
Simple equivalent: $request->filled('search')
Sourcepub fn array(&self, key: &str) -> Vec<String>
pub fn array(&self, key: &str) -> Vec<String>
Get a parameter as array (comma-separated or multiple values)
Simple equivalent: $request->input('tags', [])
Sourcepub fn pagination(&self) -> (u32, u32)
pub fn pagination(&self) -> (u32, u32)
Extract pagination parameters with sensible defaults
Returns (page, per_page) with defaults of (1, 10)
Simple equivalent: [$page, $perPage] = [$request->input('page', 1), $request->input('per_page', 10)]
Source§impl ElifRequest
impl ElifRequest
Sourcepub fn new(method: ElifMethod, uri: Uri, headers: ElifHeaderMap) -> ElifRequest
pub fn new(method: ElifMethod, uri: Uri, headers: ElifHeaderMap) -> ElifRequest
Create new ElifRequest from Axum components
Sourcepub fn extract_elif_request(
method: ElifMethod,
uri: Uri,
headers: ElifHeaderMap,
body: Option<Bytes>,
) -> ElifRequest
pub fn extract_elif_request( method: ElifMethod, uri: Uri, headers: ElifHeaderMap, body: Option<Bytes>, ) -> ElifRequest
Extract ElifRequest from request components
Sourcepub fn with_path_params(self, params: HashMap<String, String>) -> ElifRequest
pub fn with_path_params(self, params: HashMap<String, String>) -> ElifRequest
Set path parameters extracted from route
Sourcepub fn with_query_params(self, params: HashMap<String, String>) -> ElifRequest
pub fn with_query_params(self, params: HashMap<String, String>) -> ElifRequest
Set query parameters
Sourcepub fn with_body(self, body: Bytes) -> ElifRequest
pub fn with_body(self, body: Bytes) -> ElifRequest
Set request body bytes (consuming)
Sourcepub fn set_body(&mut self, body: Bytes)
pub fn set_body(&mut self, body: Bytes)
Set request body bytes (borrowing - for middleware use)
Sourcepub fn add_header<K, V>(&mut self, key: K, value: V) -> Result<(), HttpError>
pub fn add_header<K, V>(&mut self, key: K, value: V) -> Result<(), HttpError>
Add header to request (for middleware use)
Sourcepub fn add_path_param<K, V>(&mut self, key: K, value: V)
pub fn add_path_param<K, V>(&mut self, key: K, value: V)
Add path parameter (for middleware use)
Sourcepub fn add_query_param<K, V>(&mut self, key: K, value: V)
pub fn add_query_param<K, V>(&mut self, key: K, value: V)
Add query parameter (for middleware use)
Sourcepub fn path_param(&self, name: &str) -> Option<&String>
pub fn path_param(&self, name: &str) -> Option<&String>
Get path parameter by name
Sourcepub fn path_param_parsed<T>(&self, name: &str) -> Result<T, HttpError>
pub fn path_param_parsed<T>(&self, name: &str) -> Result<T, HttpError>
Get path parameter by name, parsed to specific type
Sourcepub fn query_param(&self, name: &str) -> Option<&String>
pub fn query_param(&self, name: &str) -> Option<&String>
Get query parameter by name
Sourcepub fn query_param_parsed<T>(&self, name: &str) -> Result<Option<T>, HttpError>
pub fn query_param_parsed<T>(&self, name: &str) -> Result<Option<T>, HttpError>
Get query parameter by name, parsed to specific type
Sourcepub fn query_param_required<T>(&self, name: &str) -> Result<T, HttpError>
pub fn query_param_required<T>(&self, name: &str) -> Result<T, HttpError>
Get required query parameter by name, parsed to specific type
Sourcepub fn header(&self, name: &str) -> Option<&ElifHeaderValue>
pub fn header(&self, name: &str) -> Option<&ElifHeaderValue>
Get header value by name
Sourcepub fn header_string(&self, name: &str) -> Result<Option<String>, HttpError>
pub fn header_string(&self, name: &str) -> Result<Option<String>, HttpError>
Get header value as string
Sourcepub fn body_bytes(&self) -> Option<&Bytes>
pub fn body_bytes(&self) -> Option<&Bytes>
Get request body as bytes
Sourcepub fn json<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
pub fn json<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
Parse JSON body to specified type
Sourcepub async fn json_async<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
pub async fn json_async<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
Parse JSON body to specified type (async version for consistency)
Sourcepub fn form<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
pub fn form<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
Parse form data body to specified type
Sourcepub fn query<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
pub fn query<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
Parse query parameters to specified type
Sourcepub fn path_params<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
pub fn path_params<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
Parse path parameters to specified type
Sourcepub fn query_param_as<T>(&self, name: &str) -> Result<Option<T>, HttpError>
pub fn query_param_as<T>(&self, name: &str) -> Result<Option<T>, HttpError>
Get a query parameter as a specific type
Sourcepub fn user_agent(&self) -> Option<String>
pub fn user_agent(&self) -> Option<String>
Get User-Agent header
Get Authorization header
Sourcepub fn bearer_token(&self) -> Option<String>
pub fn bearer_token(&self) -> Option<String>
Extract Bearer token from Authorization header
Sourcepub fn query_string(&self) -> Option<&str>
pub fn query_string(&self) -> Option<&str>
Get query string
Sourcepub fn extensions(&self) -> &HashMap<TypeId, Box<dyn Any + Sync + Send>>
pub fn extensions(&self) -> &HashMap<TypeId, Box<dyn Any + Sync + Send>>
Get a reference to the extensions map for reading middleware-added data
Sourcepub fn extensions_mut(
&mut self,
) -> &mut HashMap<TypeId, Box<dyn Any + Sync + Send>>
pub fn extensions_mut( &mut self, ) -> &mut HashMap<TypeId, Box<dyn Any + Sync + Send>>
Get a mutable reference to the extensions map for adding middleware data
Sourcepub fn insert_extension<T>(&mut self, data: T)
pub fn insert_extension<T>(&mut self, data: T)
Insert typed data into request extensions (helper for middleware)
Source§impl ElifRequest
Enhanced parameter extraction methods with better error handling and type safety
impl ElifRequest
Enhanced parameter extraction methods with better error handling and type safety
Sourcepub fn path_param_typed<T>(&self, name: &str) -> Result<T, ParamError>
pub fn path_param_typed<T>(&self, name: &str) -> Result<T, ParamError>
Extract and parse a path parameter with proper error handling
This is the preferred method for extracting path parameters as it provides better error messages and type safety compared to the legacy methods.
Sourcepub fn path_param_int(&self, name: &str) -> Result<i32, ParamError>
pub fn path_param_int(&self, name: &str) -> Result<i32, ParamError>
Extract and parse a path parameter as i32
Sourcepub fn path_param_u32(&self, name: &str) -> Result<u32, ParamError>
pub fn path_param_u32(&self, name: &str) -> Result<u32, ParamError>
Extract and parse a path parameter as u32
Sourcepub fn path_param_i64(&self, name: &str) -> Result<i64, ParamError>
pub fn path_param_i64(&self, name: &str) -> Result<i64, ParamError>
Extract and parse a path parameter as i64
Sourcepub fn path_param_u64(&self, name: &str) -> Result<u64, ParamError>
pub fn path_param_u64(&self, name: &str) -> Result<u64, ParamError>
Extract and parse a path parameter as u64
Sourcepub fn path_param_uuid(&self, name: &str) -> Result<Uuid, ParamError>
pub fn path_param_uuid(&self, name: &str) -> Result<Uuid, ParamError>
Extract and parse a path parameter as UUID
Sourcepub fn path_param_string(&self, name: &str) -> Result<String, ParamError>
pub fn path_param_string(&self, name: &str) -> Result<String, ParamError>
Extract and parse a path parameter as String (validates non-empty)
Sourcepub fn query_param_typed_new<T>(
&self,
name: &str,
) -> Result<Option<T>, ParamError>
pub fn query_param_typed_new<T>( &self, name: &str, ) -> Result<Option<T>, ParamError>
Extract and parse an optional query parameter with proper error handling
Sourcepub fn query_param_required_typed<T>(&self, name: &str) -> Result<T, ParamError>
pub fn query_param_required_typed<T>(&self, name: &str) -> Result<T, ParamError>
Extract and parse a required query parameter with proper error handling
Sourcepub fn query_param_int_new(&self, name: &str) -> Result<Option<i32>, ParamError>
pub fn query_param_int_new(&self, name: &str) -> Result<Option<i32>, ParamError>
Extract query parameter as optional i32
Sourcepub fn query_param_int_required(&self, name: &str) -> Result<i32, ParamError>
pub fn query_param_int_required(&self, name: &str) -> Result<i32, ParamError>
Extract query parameter as required i32
Sourcepub fn query_param_u32_new(&self, name: &str) -> Result<Option<u32>, ParamError>
pub fn query_param_u32_new(&self, name: &str) -> Result<Option<u32>, ParamError>
Extract query parameter as optional u32
Sourcepub fn query_param_u32_required(&self, name: &str) -> Result<u32, ParamError>
pub fn query_param_u32_required(&self, name: &str) -> Result<u32, ParamError>
Extract query parameter as required u32
Sourcepub fn query_param_bool_new(
&self,
name: &str,
) -> Result<Option<bool>, ParamError>
pub fn query_param_bool_new( &self, name: &str, ) -> Result<Option<bool>, ParamError>
Extract query parameter as optional bool
Sourcepub fn query_param_bool_required(&self, name: &str) -> Result<bool, ParamError>
pub fn query_param_bool_required(&self, name: &str) -> Result<bool, ParamError>
Extract query parameter as required bool
Sourcepub fn query_param_string_new(
&self,
name: &str,
) -> Result<Option<String>, ParamError>
pub fn query_param_string_new( &self, name: &str, ) -> Result<Option<String>, ParamError>
Extract query parameter as optional String
Sourcepub fn query_param_string_required(
&self,
name: &str,
) -> Result<String, ParamError>
pub fn query_param_string_required( &self, name: &str, ) -> Result<String, ParamError>
Extract query parameter as required String
Sourcepub fn validate_path_param(&self, name: &str) -> Result<&String, ParamError>
pub fn validate_path_param(&self, name: &str) -> Result<&String, ParamError>
Validate that path parameter exists and is not empty
Sourcepub fn has_path_param(&self, name: &str) -> bool
pub fn has_path_param(&self, name: &str) -> bool
Check if request has a specific path parameter
Sourcepub fn has_query_param(&self, name: &str) -> bool
pub fn has_query_param(&self, name: &str) -> bool
Check if request has a specific query parameter
Sourcepub fn path_param_names(&self) -> Vec<&String>
pub fn path_param_names(&self) -> Vec<&String>
Get all path parameter names
Sourcepub fn query_param_names(&self) -> Vec<&String>
pub fn query_param_names(&self) -> Vec<&String>
Get all query parameter names
Trait Implementations§
Source§impl Debug for ElifRequest
impl Debug for ElifRequest
Source§impl RequestIdExt for ElifRequest
impl RequestIdExt for ElifRequest
Source§fn request_id(&self) -> Option<String>
fn request_id(&self) -> Option<String>
Source§fn request_id_with_fallbacks(&self) -> Option<String>
fn request_id_with_fallbacks(&self) -> Option<String>
Source§impl RequestVersionExt for ElifRequest
impl RequestVersionExt for ElifRequest
Source§fn version_info(&self) -> Option<&VersionInfo>
fn version_info(&self) -> Option<&VersionInfo>
Source§fn api_version(&self) -> Option<&str>
fn api_version(&self) -> Option<&str>
Source§fn is_deprecated_version(&self) -> bool
fn is_deprecated_version(&self) -> bool
Auto Trait Implementations§
impl !Freeze for ElifRequest
impl !RefUnwindSafe for ElifRequest
impl Send for ElifRequest
impl Sync for ElifRequest
impl Unpin for ElifRequest
impl !UnwindSafe for ElifRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more