pub struct Request { /* private fields */ }Expand description
Represents an incoming HTTP request.
Provides high-level access to request data without exposing unsafe code. Data is lazily loaded from the host on first access.
Implementations§
Source§impl Request
impl Request
Sourcepub fn method_str(&mut self) -> String
pub fn method_str(&mut self) -> String
Returns the HTTP method as a string.
Sourcepub fn path_segments(&mut self) -> &[String]
pub fn path_segments(&mut self) -> &[String]
Returns the path split into segments. Example: “/api/users/123” -> [“api”, “users”, “123”]
Sourcepub fn path_segment(&mut self, index: usize) -> Option<&str>
pub fn path_segment(&mut self, index: usize) -> Option<&str>
Returns a specific path segment by index. Example: for “/api/users/123”, segment(1) returns Some(“users”)
Sourcepub fn query(&mut self) -> &HashMap<String, String>
pub fn query(&mut self) -> &HashMap<String, String>
Returns all query parameters as a map. If a key appears multiple times, only the last value is kept.
Sourcepub fn query_all(&mut self) -> &[(String, String)]
pub fn query_all(&mut self) -> &[(String, String)]
Returns all query parameters as a list of key-value pairs. Preserves duplicate keys.
Sourcepub fn query_param(&mut self, name: &str) -> Option<&str>
pub fn query_param(&mut self, name: &str) -> Option<&str>
Gets a query parameter by name.
Sourcepub fn headers(&mut self) -> &HashMap<String, String>
pub fn headers(&mut self) -> &HashMap<String, String>
Returns all headers as a map. Header names are lowercase.
Sourcepub fn headers_all(&mut self) -> &[(String, String)]
pub fn headers_all(&mut self) -> &[(String, String)]
Returns all headers as a list of key-value pairs.
Sourcepub fn content_type(&mut self) -> Option<&str>
pub fn content_type(&mut self) -> Option<&str>
Returns the Content-Type header value.
Returns all cookies as a map.
Gets a cookie by name.
Sourcepub fn body_string(&mut self) -> Result<String, FromUtf8Error>
pub fn body_string(&mut self) -> Result<String, FromUtf8Error>
Returns the request body as a string. Returns an error if the body is not valid UTF-8.
Sourcepub fn body_json<T: DeserializeOwned>(&mut self) -> Result<T, Error>
pub fn body_json<T: DeserializeOwned>(&mut self) -> Result<T, Error>
Parses the request body as JSON.