Skip to content

Unable to implement IntoResponse for custom body #1191

Discussion options

You must be logged in to vote

It sounds like you're misunderstanding some concepts:

  • A response body is something that implements http_body::Body. This is a low level trait that requires dealing with pinning and such. Response bodies cannot set headers since its just a body. I don't think this is what you're looking for.
  • A response is something that implements IntoResponse. It can set status, headers, and response body. Json is a response that will convert some T: serde::Serialize into JSON, set a content-type: application/json header, and return that.

From the code you posted it looks like you just wanna return some JSON. In which case you should just use axum::Json(...). Just make sure your type implements serde::S…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SiddheshKanawade
Comment options

Answer selected by davidpdrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants