Skip to main content

RequestData

Struct RequestData 

Source
pub struct RequestData {
    pub uri: Uri,
    pub method: String,
    pub headers: Headers,
    pub body: BodyData,
    pub cookies: Cookies,
}
Expand description

Represents an incoming HTTP request.

This struct contains all the relevant information about an HTTP request, including the request method, URI, headers, body, and cookies. It can be accessed in an endpoint or middleware function to inspect or modify the request before generating a response.

Fields§

§uri: Uri

The URI of the request, including host, path, query parameters, and scheme.

This contains detailed information about the requested resource.

§Example

A request to http://example.org:3000/hello/world?name=John will have:

  • uri.host = Some("example.org".to_string())
  • uri.path = "/hello/world".to_string()
  • uri.query = Some("name=John".to_string())
  • uri.query_map = Some(HashMap::from([("name".to_string(), "John".to_string())]))
  • uri.port = Some(3000)
  • uri.scheme = Some("http".to_string())
§method: String

The HTTP method of the request (e.g., "get", "post", "put", etc.).

This indicates the action the client wants to perform on the requested resource.

§Example

use awpak_rs::io::request::request_data::RequestData;
 
let request_data = RequestData::default();
 
if request_data.method == "post" {
    println!("Handling a POST request");
}
§headers: Headers

The headers included in the request.

Headers provide metadata about the request, such as content type, authentication tokens, or caching information.

§Example: Checking for an Authorization header

use awpak_rs::io::request::request_data::RequestData;
 
let request_data = RequestData::default();
 
if let Some(auth_header) = request_data.headers.get_value("Authorization") {
    println!("Authorization: {}", auth_header);
}
§body: BodyData

The body of the request.

The request body will be stored in body.value. If the request is a multipart/form-data upload, the files will be available in body.files.

§Example: Accessing JSON data

use awpak_rs::io::request::request_data::RequestData;
 
let request_data = RequestData::default();

if let Some(json_body) = &request_data.body.value {
    println!("Received JSON: {}", json_body);
}

§Example: Handling file uploads

ⓘ
for file in &request_data.body.files {
    println!("Received file: {}", file.filename);
}
§cookies: Cookies

The cookies included in the request.

Cookies are stored as key-value pairs and can be used for session management, authentication, or storing user preferences.

use awpak_rs::io::request::request_data::RequestData;
 
let request_data = RequestData::default();
 
if let Some(cookie) = request_data.cookies.find_first_by_name("session_id") {
    println!("Session ID: {}", cookie.value());
}

Implementations§

Source§

impl RequestData

Source

pub fn new( uri: Uri, method: String, headers: Headers, cookies: Cookies, body: BodyData, ) -> Self

Source

pub fn get_headers(&self) -> Headers

Source

pub fn get_cookies(&self) -> Cookies

Trait Implementations§

Source§

impl Default for RequestData

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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