1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/// Web service that receives and responds with HTML.
///
/// ## Overview
///
/// Tower web supports templates and responding with HTML using the handlebars
/// templating engine. Plain old Rust structs are used to represent data and
/// are used as the handler return value. Tower Web passes the response structs
/// to the handlebars serializer. HTML is rendered using a handlebars template
/// and populated using the data in the response struct.
///
/// ## Usage
///
/// Run the example:
///
/// cargo run --example html_handlebars
///
/// Then send a request:
///
/// curl -v http://localhost:8080/
extern crate env_logger;
extern crate tower_web;
extern crate tokio;
use ServiceBuilder;
use Handlebars;
/// This type will be the web service implementation.
;
/// The type is annotated with `#[derive(Response)]`, this allows `MyResponse`
/// to be used as a response to resource methods.
///
/// We are using the handlebars serializer to render the HTML response. It
/// requires that a template to render is specified. This is done with the
/// `#[web(template = "<template name>")]` attribute.
///
/// The default location to look for templates is in the `templates` directory
/// at the crate root. To make the example work, this crate has a handlebars
/// template at "examples/hello_world.hbs" in the templates directory at the
/// crate root.
impl_web!