title: How to get the body of a Response in actix_web unit test?
body: <p>I'm building a web API service with Rust and actix_web.</p>
  <p>I want to test a route and check if the received response body is what I expect. But I'm struggling with converting the received body <code>ResponseBody&lt;Body&gt;</code> into JSON or BSON. The called route actually returns <code>application/json</code>.</p>
  <pre><code>let mut app = test::init_service(App::new()
          .data(AppState { database: db.clone() })
          .route(&quot;/recipes/{id}&quot;, web::post().to(add_one_recipe))
      ).await;
  
  let payload = create_one_recipe().as_document().unwrap().clone();
  
  let req = test::TestRequest::post()
      .set_json(&amp;payload).uri(&quot;/recipes/new&quot;).to_request();
  
  let mut resp = test::call_service(&amp;mut app, req).await;
  let body: ResponseBody&lt;Body&gt; = resp.take_body(); // Here I want the body as Binary, String, JSON, or BSON. The response is actually application/json.
  </code></pre>