README.asciidoc 10 KB

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