-
Here is my custom response: #[derive(Serialize)]
pub struct ApiResponse<T> {
code: u16,
message: String,
detail: Option<T>
} And there is my implemention: impl<T: Serialize> Responder for ApiResponse<T> {
type Body = BoxBody;
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body> {
let body = serde_json::to_string(&self).unwrap();
HttpResponse::Ok()
.content_type("application/json")
.body(body)
}
} It works, but i don't know that is the true way. It should include sth like future ? |
Beta Was this translation helpful? Give feedback.
Answered by
robjtede
Jul 8, 2024
Replies: 1 comment 1 reply
-
Looks good. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
un4gt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good.
Response
is not an async trait, but it's body types are allowed to beStream
s.