Why so many body types? #192
-
Hello, maybe the same question for request/response types:
Just to compare, axum/hyper uses a single type, from the Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
because real world http types are complicated. In order to express them you either have a single type with compromise or use specialized types for low overhead. let's take a very common use case for example: struct Reject<S> {
service: S,
}
// ignore the unconstraint B type.
impl<S, B> Service<Request> for Reject<S>
where
S: Service<Request, Response = Response<B>>
{
async fn call(&self, req: Request) -> Result<Response<B>, Error> {
if req.path != "/" {
return Ok(Response::new(<what_type_is_this>))
}
self.service.call(req).await
}
} in ntex you can express it with |
Beta Was this translation helpful? Give feedback.
-
As for |
Beta Was this translation helpful? Give feedback.
As for
Payload
type the benefit of separating request/response body type is mainly you can relax theUnpin
bound. From server's view request body type can be alwaysUnpin
while response body type can be!Unpin
for special body use. This is not something often used but it leaves the possibility open. From client's view this still holds in reverse order.