kit_rs/http/
request.rs

1use std::collections::HashMap;
2
3/// HTTP Request wrapper providing Laravel-like access to request data
4pub struct Request {
5    inner: hyper::Request<hyper::body::Incoming>,
6    params: HashMap<String, String>,
7}
8
9impl Request {
10    pub fn new(inner: hyper::Request<hyper::body::Incoming>) -> Self {
11        Self {
12            inner,
13            params: HashMap::new(),
14        }
15    }
16
17    pub fn with_params(mut self, params: HashMap<String, String>) -> Self {
18        self.params = params;
19        self
20    }
21
22    /// Get the request method
23    pub fn method(&self) -> &hyper::Method {
24        self.inner.method()
25    }
26
27    /// Get the request path
28    pub fn path(&self) -> &str {
29        self.inner.uri().path()
30    }
31
32    /// Get a route parameter by name (e.g., /users/{id})
33    pub fn param(&self, name: &str) -> Option<&String> {
34        self.params.get(name)
35    }
36
37    /// Get all route parameters
38    pub fn params(&self) -> &HashMap<String, String> {
39        &self.params
40    }
41
42    /// Get the inner hyper request
43    pub fn inner(&self) -> &hyper::Request<hyper::body::Incoming> {
44        &self.inner
45    }
46}