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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/// Hello world service.
///
/// A simple service that demonstrates how to get started with `tower-web`.
///
/// ## Overview
///
/// `tower-web` lets you define a web service using "plain old Rust types"
/// (PORT). The idea is to decouple all HTTP concepts from the business logic.
/// This is achieved by using macros that inspect the handler functions on your
/// PORT and generate a [Tower `Service`][service] implementation.
///
/// `tower-web` removes most of the boiler plate from implementing web apps by
/// embracing convention over configuration.
///
/// [service]: https://github.com/tower-rs/tower
///
/// ## Service and Resources
///
/// First, some quick terminology.
///
/// A "service" is a type that receives and responds to HTTP requests. A "route"
/// is a specific mapping from an HTTP request to a function handler. A
/// "resource" is a bundle of routes. A "service" is one or more resources.
///
/// For example, a single service might have the following resources:
///
/// * User
/// * Article
/// * Comment
///
/// Each one of those resources would have multiple routes, including, but not
/// limited to:
///
/// * User::list
/// * User::create
/// * User::update
/// * Article::show
/// * Comment::delete
///
/// ## Usage
///
/// Run the example:
///
/// cargo run --example hello_world
///
/// Then send a request:
///
/// curl -v http://localhost:8080/
extern crate tower_web;
extern crate tokio;
use ServiceBuilder;
use *;
/// This type will be part of the web service as a resource.
/// To derive `Resource`, the implementation of `HelloWorld` is contained in the
/// `impl_web!` macro. This macro does not modify any of its contents. It will
/// inspect the implementation and, with the help of some annotations, generate
/// the necessary glue code to run the web service.
///
/// impl_web! is a temporary solution to enable tower-web to work with stable
/// rust. In the near future, this will be transitioned to use attribute macros.
impl_web!