Reputation: 621
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.
Upvotes: 0
Views: 1012
Reputation: 154
Same as in first example, just replace .content_type() with .set()
Upvotes: 0