What is the best practice in actix-web to returning a response

I'm migrating from Java to Rust

In the Java world, when I code Spring, I often create a class called RestBean and wrap every response with it to get a json response like this

{
  "code": 200,
  "body": {/*some data*/},
  "message": "ok"
}

I learnt this trick from a very outdated tutorial, I know is not the best practice.

But Rust is not Java, I think there is a more unified way to do that.

Should I keep wrapping the response with something like RestBean or stop doing that?

PS: returning the status code in json could be duplicated with the HTTP status code, which is not the best practice.

As you said, duplicating the status code from the header in the body is a bit odd. But how you design your API should be guided by your requirements and not what technology you are using. You certainly can create such a wrapper type in actix-web. A type RestBean that implements Responder (similar to the built-in Json responder), which you can return from your endpoints, would be the most straight-forward implementation. You could also create a middleware that wraps your endpoints, but I don't recommend that, as extracting the response body from your endpoint in the middleware is cumbersome, complex and brittle.

I'll try it later, thanks