pub struct Request<T, C = ()> {
pub body: T,
pub ctx: C,
pub headers: HeaderMap,
pub method: Method,
pub path: String,
pub path_params: HashMap<String, String>,
pub query_params: HashMap<String, String>,
pub request_id: String,
}Expand description
HTTP request wrapper providing context alongside the deserialized body
The generic parameter T is the request body type (flatbed-generated struct).
The optional parameter C is the application context type (defaults to ()).
§Example
ⓘ
// Simple handler without context
#[route("/ping")]
async fn handle_ping(req: Request<PingRequest>) -> Result<Response<PingResponse>, FlatbedError> {
Ok(Response::ok(PingResponse { message: Some("pong".into()), ... }))
}
// Handler with application context
#[route("/users")]
async fn handle_users(req: Request<UserRequest, AppCtx>) -> Result<Response<UserResponse>, FlatbedError> {
let user = req.ctx.db.find_user(&req.body.id).await?;
Ok(Response::ok(UserResponse { name: user.name, ... }))
}Fields§
§body: TThe deserialized request body
ctx: CApplication context (zero-sized when C = ())
headers: HeaderMapHTTP headers from the request
method: MethodHTTP method
path: StringRequest path
path_params: HashMap<String, String>Path parameters (e.g., /users/{id} -> {“id”: “123”})
query_params: HashMap<String, String>Query string parameters
request_id: StringRequest ID (propagated or generated)
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T, C> Freeze for Request<T, C>
impl<T, C> RefUnwindSafe for Request<T, C>where
T: RefUnwindSafe,
C: RefUnwindSafe,
impl<T, C> Send for Request<T, C>
impl<T, C> Sync for Request<T, C>
impl<T, C> Unpin for Request<T, C>
impl<T, C> UnsafeUnpin for Request<T, C>where
T: UnsafeUnpin,
C: UnsafeUnpin,
impl<T, C> UnwindSafe for Request<T, C>where
T: UnwindSafe,
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more