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: UriThe 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: StringThe 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: HeadersThe 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: BodyDataThe 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);
}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.
§Example: Retrieving a cookie by name
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());
}