Debian Codegraph @

examples/rest_hello_world/README.asciidoc

raw
1 = REST hello world example
2
3 To try this example, you need GNU `make` and `git` in your PATH.
4
5 To build and run the example, use the following command:
6
7 [source,bash]
8 $ make run
9
10 Then point your browser to http://localhost:8080
11
12 == HTTP/1.1 example output
13
14 Request HTML:
15
16 [source,bash]
17 ----
18 $ curl -i http://localhost:8080
19 HTTP/1.1 200 OK
20 connection: keep-alive
21 server: Cowboy
22 date: Fri, 28 Sep 2012 04:15:52 GMT
23 content-length: 136
24 content-type: text/html
25 vary: Accept
26
27 <html>
28 <head>
29 <meta charset="utf-8">
30 <title>REST Hello World!</title>
31 </head>
32 <body>
33 <p>REST Hello World as HTML!</p>
34 </body>
35 </html>
36 ----
37
38 Request JSON:
39
40 [source,bash]
41 ----
42 $ curl -i -H "Accept: application/json" http://localhost:8080
43 HTTP/1.1 200 OK
44 connection: keep-alive
45 server: Cowboy
46 date: Fri, 28 Sep 2012 04:16:46 GMT
47 content-length: 24
48 content-type: application/json
49 vary: Accept
50
51 {"rest": "Hello World!"}
52 ----
53
54 Request plain text:
55
56 [source,bash]
57 ----
58 $ curl -i -H "Accept: text/plain" http://localhost:8080
59 HTTP/1.1 200 OK
60 connection: keep-alive
61 server: Cowboy
62 date: Fri, 28 Sep 2012 04:18:35 GMT
63 content-length: 25
64 content-type: text/plain
65 vary: Accept
66
67 REST Hello World as text!
68 ----
69
70 Request a non acceptable content-type:
71
72 [source,bash]
73 ----
74 $ curl -i -H "Accept: text/css" http://localhost:8080
75 HTTP/1.1 406 Not Acceptable
76 connection: keep-alive
77 server: Cowboy
78 date: Fri, 28 Sep 2012 04:18:51 GMT
79 content-length: 0
80
81 ----
82
83 == HTTP/2 example output
84
85 Request HTML:
86
87 [source,bash]
88 ----
89 $ nghttp -v http://localhost:8080
90 [ 0.000] Connected
91 [ 0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
92 (niv=2)
93 [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
94 [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
95 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
96 (dep_stream_id=0, weight=201, exclusive=0)
97 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
98 (dep_stream_id=0, weight=101, exclusive=0)
99 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
100 (dep_stream_id=0, weight=1, exclusive=0)
101 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
102 (dep_stream_id=7, weight=1, exclusive=0)
103 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
104 (dep_stream_id=3, weight=1, exclusive=0)
105 [ 0.000] send HEADERS frame <length=38, flags=0x25, stream_id=13>
106 ; END_STREAM | END_HEADERS | PRIORITY
107 (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
108 ; Open new stream
109 :method: GET
110 :path: /
111 :scheme: http
112 :authority: localhost:8080
113 accept: */*
114 accept-encoding: gzip, deflate
115 user-agent: nghttp2/1.7.1
116 [ 0.000] recv SETTINGS frame <length=0, flags=0x00, stream_id=0>
117 (niv=0)
118 [ 0.000] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
119 ; ACK
120 (niv=0)
121 [ 0.000] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
122 ; ACK
123 (niv=0)
124 [ 0.001] recv (stream_id=13) :status: 200
125 [ 0.001] recv (stream_id=13) content-length: 136
126 [ 0.001] recv (stream_id=13) content-type: text/html
127 [ 0.001] recv (stream_id=13) date: Thu, 09 Jun 2016 14:28:50 GMT
128 [ 0.001] recv (stream_id=13) server: Cowboy
129 [ 0.001] recv (stream_id=13) vary: accept
130 [ 0.001] recv HEADERS frame <length=52, flags=0x04, stream_id=13>
131 ; END_HEADERS
132 (padlen=0)
133 ; First response header
134 <html>
135 <head>
136 <meta charset="utf-8">
137 <title>REST Hello World!</title>
138 </head>
139 <body>
140 <p>REST Hello World as HTML!</p>
141 </body>
142 </html>[ 0.001] recv DATA frame <length=136, flags=0x01, stream_id=13>
143 ; END_STREAM
144 [ 0.001] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
145 (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
146 ----
147
148 Request JSON:
149
150 [source,bash]
151 ----
152 $ nghttp -v -H "accept: application/json" http://localhost:8080
153 [ 0.000] Connected
154 [ 0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
155 (niv=2)
156 [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
157 [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
158 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
159 (dep_stream_id=0, weight=201, exclusive=0)
160 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
161 (dep_stream_id=0, weight=101, exclusive=0)
162 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
163 (dep_stream_id=0, weight=1, exclusive=0)
164 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
165 (dep_stream_id=7, weight=1, exclusive=0)
166 [ 0.001] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
167 (dep_stream_id=3, weight=1, exclusive=0)
168 [ 0.001] send HEADERS frame <length=46, flags=0x25, stream_id=13>
169 ; END_STREAM | END_HEADERS | PRIORITY
170 (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
171 ; Open new stream
172 :method: GET
173 :path: /
174 :scheme: http
175 :authority: localhost:8080
176 accept: application/json
177 accept-encoding: gzip, deflate
178 user-agent: nghttp2/1.7.1
179 [ 0.001] recv SETTINGS frame <length=0, flags=0x00, stream_id=0>
180 (niv=0)
181 [ 0.001] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
182 ; ACK
183 (niv=0)
184 [ 0.001] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
185 ; ACK
186 (niv=0)
187 [ 0.001] recv (stream_id=13) :status: 200
188 [ 0.001] recv (stream_id=13) content-length: 24
189 [ 0.001] recv (stream_id=13) content-type: application/json
190 [ 0.001] recv (stream_id=13) date: Thu, 09 Jun 2016 14:29:00 GMT
191 [ 0.001] recv (stream_id=13) server: Cowboy
192 [ 0.001] recv (stream_id=13) vary: accept
193 [ 0.001] recv HEADERS frame <length=55, flags=0x04, stream_id=13>
194 ; END_HEADERS
195 (padlen=0)
196 ; First response header
197 {"rest": "Hello World!"}[ 0.002] recv DATA frame <length=24, flags=0x01, stream_id=13>
198 ; END_STREAM
199 [ 0.002] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
200 (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
201 ----
202
203 Request plain text:
204
205 [source,bash]
206 ----
207 $ nghttp -v -H "accept: text/plain" http://localhost:8080
208 [ 0.000] Connected
209 [ 0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
210 (niv=2)
211 [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
212 [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
213 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
214 (dep_stream_id=0, weight=201, exclusive=0)
215 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
216 (dep_stream_id=0, weight=101, exclusive=0)
217 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
218 (dep_stream_id=0, weight=1, exclusive=0)
219 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
220 (dep_stream_id=7, weight=1, exclusive=0)
221 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
222 (dep_stream_id=3, weight=1, exclusive=0)
223 [ 0.000] send HEADERS frame <length=42, flags=0x25, stream_id=13>
224 ; END_STREAM | END_HEADERS | PRIORITY
225 (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
226 ; Open new stream
227 :method: GET
228 :path: /
229 :scheme: http
230 :authority: localhost:8080
231 accept: text/plain
232 accept-encoding: gzip, deflate
233 user-agent: nghttp2/1.7.1
234 [ 0.000] recv SETTINGS frame <length=0, flags=0x00, stream_id=0>
235 (niv=0)
236 [ 0.000] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
237 ; ACK
238 (niv=0)
239 [ 0.000] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
240 ; ACK
241 (niv=0)
242 [ 0.000] recv (stream_id=13) :status: 200
243 [ 0.000] recv (stream_id=13) content-length: 25
244 [ 0.000] recv (stream_id=13) content-type: text/plain
245 [ 0.000] recv (stream_id=13) date: Thu, 09 Jun 2016 14:28:25 GMT
246 [ 0.000] recv (stream_id=13) server: Cowboy
247 [ 0.000] recv (stream_id=13) vary: accept
248 [ 0.000] recv HEADERS frame <length=51, flags=0x04, stream_id=13>
249 ; END_HEADERS
250 (padlen=0)
251 ; First response header
252 REST Hello World as text![ 0.000] recv DATA frame <length=25, flags=0x01, stream_id=13>
253 ; END_STREAM
254 [ 0.000] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
255 (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
256 ----
257
258 Request a non acceptable content-type:
259
260 [source,bash]
261 ----
262 $ nghttp -v -H "accept: text/css" http://localhost:8080
263 [ 0.000] Connected
264 [ 0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
265 (niv=2)
266 [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
267 [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
268 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
269 (dep_stream_id=0, weight=201, exclusive=0)
270 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
271 (dep_stream_id=0, weight=101, exclusive=0)
272 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
273 (dep_stream_id=0, weight=1, exclusive=0)
274 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
275 (dep_stream_id=7, weight=1, exclusive=0)
276 [ 0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
277 (dep_stream_id=3, weight=1, exclusive=0)
278 [ 0.000] send HEADERS frame <length=41, flags=0x25, stream_id=13>
279 ; END_STREAM | END_HEADERS | PRIORITY
280 (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
281 ; Open new stream
282 :method: GET
283 :path: /
284 :scheme: http
285 :authority: localhost:8080
286 accept: text/css
287 accept-encoding: gzip, deflate
288 user-agent: nghttp2/1.7.1
289 [ 0.007] recv SETTINGS frame <length=0, flags=0x00, stream_id=0>
290 (niv=0)
291 [ 0.007] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
292 ; ACK
293 (niv=0)
294 [ 0.007] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
295 ; ACK
296 (niv=0)
297 [ 0.021] recv (stream_id=13) :status: 406
298 [ 0.021] recv (stream_id=13) content-length: 0
299 [ 0.021] recv (stream_id=13) date: Thu, 09 Jun 2016 14:29:15 GMT
300 [ 0.021] recv (stream_id=13) server: Cowboy
301 [ 0.021] recv HEADERS frame <length=39, flags=0x04, stream_id=13>
302 ; END_HEADERS
303 (padlen=0)
304 ; First response header
305 [ 0.021] recv DATA frame <length=0, flags=0x01, stream_id=13>
306 ; END_STREAM
307 [ 0.021] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
308 (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])
309 ----