title: How can I create an application/json HTTPResponse in actix?
body: <p>In the <code>example</code> <a href="https://github.com/actix/examples/blob/master/basics/src/main.rs#L57" rel="nofollow noreferrer">section</a>, they use:</p>
  
  <pre><code>HttpResponse::Ok()
      .content_type("text/plain")
      .body(format!("Hello {}!", req.match_info().get("name").unwrap()))
  </code></pre>
  
  <p>Yet I don't like to hardcode my <code>content-type</code> since there's a nice <a href="https://github.com/actix/actix-web/blob/master/src/header/common/content_type.rs#L54" rel="nofollow noreferrer">class</a> that shows I can use an enum for the <code>json</code> response:</p>
  
  <pre><code>let mut builder = HttpResponse::Ok();
  builder.set(ContentType(TEXT_HTML));
  </code></pre>
  
  <p>The problem is that I want to set the response's body as well. How can I do it in <code>builder</code> above?</p>
  
  <p>Thanks.</p>