How to use Response<BoxBody> with and without json payload in actix_http v3? #2676
-
It seems that with upgrade to actix_http v3 we can use e.g. I've tried with actix_http::Response::new(actix_http::StatusCode::OK).set_body(
web::Json( __MY_STRUCT_IMPLEMENTING_derive_Deserialize__ {
...
})
).map_into_boxed_body() but then I get:
Relevant piece of code I'm trying to migrate: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Firstly familiarize yourself with the body type changes in v4 explained here. Also it would be helpful to use Eg: - None => return actix_http::Response::BadRequest().body(Body::Empty),
+ None => return actix_web::HttpResponse::BadRequest().finish(),
- actix_http::Response::Ok().json(CollectorRegisterRespone {
+ actix_web::HttpResponse::Ok().json(CollectorRegisterRespone { |
Beta Was this translation helpful? Give feedback.
-
Thanks @robjtede! That worked and I wasn't aware of this guide 😬 |
Beta Was this translation helpful? Give feedback.
Firstly familiarize yourself with the body type changes in v4 explained here. Also it would be helpful to use
HttpResponse
from Actix Web instead of theactix-http
types in your case since it contains fewer high-level things now.Eg: