0

In the example section, they use:

HttpResponse::Ok()
    .content_type("text/plain")
    .body(format!("Hello {}!", req.match_info().get("name").unwrap()))

Yet I don't like to hardcode my content-type since there's a nice class that shows I can use an enum for the json response:

let mut builder = HttpResponse::Ok();
builder.set(ContentType(TEXT_HTML));

The problem is that I want to set the response's body as well. How can I do it in builder above?

Thanks.

James Larkin
  • 541
  • 5
  • 18

1 Answers1

0

Same as in first example, just replace .content_type() with .set()

Nikolay Kim
  • 144
  • 1