Request

Struct Request 

Source
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

Source

pub fn input<T>(&self, key: &str, default: T) -> T
where T: FromStr + Clone, <T as FromStr>::Err: Debug,

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)

Source

pub fn input_optional<T>(&self, key: &str) -> Option<T>
where T: FromStr, <T as FromStr>::Err: Debug,

Simple input extraction that returns Option

Simple equivalent: $request->input('search')

Source

pub fn string(&self, key: &str, default: &str) -> String

Extract a string input with default

Simple equivalent: $request->input('name', 'default')

Source

pub fn string_optional(&self, key: &str) -> Option<String>

Extract an optional string input

Simple equivalent: $request->input('search')

Source

pub fn integer(&self, key: &str, default: i64) -> i64

Extract an integer input with default

Simple equivalent: $request->input('page', 1)

Source

pub fn integer_optional(&self, key: &str) -> Option<i64>

Extract an optional integer input

Simple equivalent: $request->input('limit')

Source

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)

Source

pub fn inputs(&self, keys: &[&str]) -> HashMap<String, String>

Extract multiple inputs at once as a HashMap

Simple equivalent: $request->only(['name', 'email', 'age'])

Source

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

Extract all query parameters as HashMap

Simple equivalent: $request->query()

Source

pub fn has(&self, key: &str) -> bool

Check if a parameter exists (in query or path)

Simple equivalent: $request->has('search')

Source

pub fn filled(&self, key: &str) -> bool

Check if a parameter exists and is not empty

Simple equivalent: $request->filled('search')

Source

pub fn array(&self, key: &str) -> Vec<String>

Get a parameter as array (comma-separated or multiple values)

Simple equivalent: $request->input('tags', [])

Source

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

pub fn sorting(&self, default_field: &str) -> (String, String)

Extract sorting parameters

Returns (sort_field, sort_direction) with defaults Simple equivalent: [$sort, $order] = [$request->input('sort', 'id'), $request->input('order', 'asc')]

Source

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

Extract search and filtering parameters

Returns a HashMap of common filter parameters Simple equivalent: $filters = $request->only(['search', 'status', 'category'])

Source§

impl ElifRequest

Source

pub fn new(method: ElifMethod, uri: Uri, headers: ElifHeaderMap) -> ElifRequest

Create new ElifRequest from Axum components

Source

pub fn extract_elif_request( method: ElifMethod, uri: Uri, headers: ElifHeaderMap, body: Option<Bytes>, ) -> ElifRequest

Extract ElifRequest from request components

Source

pub fn with_path_params(self, params: HashMap<String, String>) -> ElifRequest

Set path parameters extracted from route

Source

pub fn with_query_params(self, params: HashMap<String, String>) -> ElifRequest

Set query parameters

Source

pub fn with_body(self, body: Bytes) -> ElifRequest

Set request body bytes (consuming)

Source

pub fn set_body(&mut self, body: Bytes)

Set request body bytes (borrowing - for middleware use)

Source

pub fn add_header<K, V>(&mut self, key: K, value: V) -> Result<(), HttpError>
where K: AsRef<str>, V: AsRef<str>,

Add header to request (for middleware use)

Source

pub fn add_path_param<K, V>(&mut self, key: K, value: V)
where K: Into<String>, V: Into<String>,

Add path parameter (for middleware use)

Source

pub fn add_query_param<K, V>(&mut self, key: K, value: V)
where K: Into<String>, V: Into<String>,

Add query parameter (for middleware use)

Source

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

Get path parameter by name

Source

pub fn path_param_parsed<T>(&self, name: &str) -> Result<T, HttpError>
where T: FromStr, <T as FromStr>::Err: Display,

Get path parameter by name, parsed to specific type

Source

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

Get query parameter by name

Source

pub fn query_param_parsed<T>(&self, name: &str) -> Result<Option<T>, HttpError>
where T: FromStr, <T as FromStr>::Err: Display,

Get query parameter by name, parsed to specific type

Source

pub fn query_param_required<T>(&self, name: &str) -> Result<T, HttpError>
where T: FromStr, <T as FromStr>::Err: Display,

Get required query parameter by name, parsed to specific type

Source

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

Get header value by name

Source

pub fn header_string(&self, name: &str) -> Result<Option<String>, HttpError>

Get header value as string

Source

pub fn content_type(&self) -> Result<Option<String>, HttpError>

Get Content-Type header

Source

pub fn is_json(&self) -> bool

Check if request has JSON content type

Source

pub fn body_bytes(&self) -> Option<&Bytes>

Get request body as bytes

Source

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

Parse JSON body to specified type

Source

pub async fn json_async<T>(&self) -> Result<T, HttpError>

Parse JSON body to specified type (async version for consistency)

Source

pub fn form<T>(&self) -> Result<T, HttpError>

Parse form data body to specified type

Source

pub fn query<T>(&self) -> Result<T, HttpError>

Parse query parameters to specified type

Source

pub fn path_params<T>(&self) -> Result<T, HttpError>

Parse path parameters to specified type

Source

pub fn query_param_as<T>(&self, name: &str) -> Result<Option<T>, HttpError>
where T: FromStr, <T as FromStr>::Err: Display,

Get a query parameter as a specific type

Source

pub fn user_agent(&self) -> Option<String>

Get User-Agent header

Source

pub fn authorization(&self) -> Option<String>

Get Authorization header

Source

pub fn bearer_token(&self) -> Option<String>

Extract Bearer token from Authorization header

Source

pub fn client_ip(&self) -> Option<String>

Get request IP address from headers or connection

Source

pub fn is_secure(&self) -> bool

Check if request is HTTPS

Source

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

Get request host

Source

pub fn path(&self) -> &str

Get request path

Source

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

Get query string

Source

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

Get a reference to the extensions map for reading middleware-added data

Source

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

Source

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

Insert typed data into request extensions (helper for middleware)

Source

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

Get typed data from request extensions (helper for middleware)

Source§

impl ElifRequest

Enhanced parameter extraction methods with better error handling and type safety

Source

pub fn path_param_typed<T>(&self, name: &str) -> Result<T, ParamError>
where T: FromStr, <T as FromStr>::Err: Debug + Display,

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.

Source

pub fn path_param_int(&self, name: &str) -> Result<i32, ParamError>

Extract and parse a path parameter as i32

Source

pub fn path_param_u32(&self, name: &str) -> Result<u32, ParamError>

Extract and parse a path parameter as u32

Source

pub fn path_param_i64(&self, name: &str) -> Result<i64, ParamError>

Extract and parse a path parameter as i64

Source

pub fn path_param_u64(&self, name: &str) -> Result<u64, ParamError>

Extract and parse a path parameter as u64

Source

pub fn path_param_uuid(&self, name: &str) -> Result<Uuid, ParamError>

Extract and parse a path parameter as UUID

Source

pub fn path_param_string(&self, name: &str) -> Result<String, ParamError>

Extract and parse a path parameter as String (validates non-empty)

Source

pub fn query_param_typed_new<T>( &self, name: &str, ) -> Result<Option<T>, ParamError>
where T: FromStr, <T as FromStr>::Err: Debug + Display,

Extract and parse an optional query parameter with proper error handling

Source

pub fn query_param_required_typed<T>(&self, name: &str) -> Result<T, ParamError>
where T: FromStr, <T as FromStr>::Err: Debug + Display,

Extract and parse a required query parameter with proper error handling

Source

pub fn query_param_int_new(&self, name: &str) -> Result<Option<i32>, ParamError>

Extract query parameter as optional i32

Source

pub fn query_param_int_required(&self, name: &str) -> Result<i32, ParamError>

Extract query parameter as required i32

Source

pub fn query_param_u32_new(&self, name: &str) -> Result<Option<u32>, ParamError>

Extract query parameter as optional u32

Source

pub fn query_param_u32_required(&self, name: &str) -> Result<u32, ParamError>

Extract query parameter as required u32

Source

pub fn query_param_bool_new( &self, name: &str, ) -> Result<Option<bool>, ParamError>

Extract query parameter as optional bool

Source

pub fn query_param_bool_required(&self, name: &str) -> Result<bool, ParamError>

Extract query parameter as required bool

Source

pub fn query_param_string_new( &self, name: &str, ) -> Result<Option<String>, ParamError>

Extract query parameter as optional String

Source

pub fn query_param_string_required( &self, name: &str, ) -> Result<String, ParamError>

Extract query parameter as required String

Source

pub fn validate_path_param(&self, name: &str) -> Result<&String, ParamError>

Validate that path parameter exists and is not empty

Source

pub fn has_path_param(&self, name: &str) -> bool

Check if request has a specific path parameter

Source

pub fn has_query_param(&self, name: &str) -> bool

Check if request has a specific query parameter

Source

pub fn path_param_names(&self) -> Vec<&String>

Get all path parameter names

Source

pub fn query_param_names(&self) -> Vec<&String>

Get all query parameter names

Trait Implementations§

Source§

impl Debug for ElifRequest

Source§

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

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

impl RequestIdExt for ElifRequest

Source§

fn request_id(&self) -> Option<String>

Get the request ID from the request headers
Source§

fn request_id_with_fallbacks(&self) -> Option<String>

Get the request ID with fallback header names
Source§

impl RequestVersionExt for ElifRequest

Source§

fn version_info(&self) -> Option<&VersionInfo>

Get version information from request
Source§

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

Get current API version string
Source§

fn is_deprecated_version(&self) -> bool

Check if current version is deprecated

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,