From 394b4f0bf7f2a4d496ffe69c8e30cff153d69532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 14 Jan 2016 20:00:50 +0100 Subject: Simplify example instructions and fix broken examples Also convert to AsciiDoc while we're at it. --- examples/chunked_hello_world/README.asciidoc | 28 ++++++++ examples/chunked_hello_world/README.md | 36 ---------- examples/compress_response/README.asciidoc | 63 +++++++++++++++++ examples/compress_response/README.md | 70 ------------------- examples/cookie/README.asciidoc | 13 ++++ examples/cookie/README.md | 20 ------ examples/echo_get/README.asciidoc | 28 ++++++++ examples/echo_get/README.md | 36 ---------- examples/echo_post/README.asciidoc | 28 ++++++++ examples/echo_post/README.md | 36 ---------- examples/error_hook/README.asciidoc | 47 +++++++++++++ examples/error_hook/README.md | 54 --------------- examples/eventsource/README.asciidoc | 10 +++ examples/eventsource/README.md | 19 ------ examples/hello_world/README.asciidoc | 25 +++++++ examples/hello_world/README.md | 33 --------- examples/markdown_middleware/README.asciidoc | 15 +++++ examples/markdown_middleware/README.md | 24 ------- examples/rest_basic_auth/README.asciidoc | 40 +++++++++++ examples/rest_basic_auth/README.md | 47 ------------- examples/rest_basic_auth/src/toppage_handler.erl | 2 +- examples/rest_hello_world/README.asciidoc | 81 ++++++++++++++++++++++ examples/rest_hello_world/README.md | 86 ------------------------ examples/rest_pastebin/README.asciidoc | 47 +++++++++++++ examples/rest_pastebin/README.md | 60 ----------------- examples/rest_pastebin/src/toppage_handler.erl | 6 +- examples/rest_stream_response/README.asciidoc | 67 ++++++++++++++++++ examples/rest_stream_response/README.md | 74 -------------------- examples/ssl_hello_world/README.asciidoc | 27 ++++++++ examples/ssl_hello_world/README.md | 34 ---------- examples/static_world/README.asciidoc | 30 +++++++++ examples/static_world/README.md | 38 ----------- examples/upload/README.asciidoc | 12 ++++ examples/upload/README.md | 20 ------ examples/web_server/README.asciidoc | 11 +++ examples/web_server/README.md | 19 ------ examples/websocket/README.asciidoc | 10 +++ examples/websocket/README.md | 18 ----- 38 files changed, 586 insertions(+), 728 deletions(-) create mode 100644 examples/chunked_hello_world/README.asciidoc delete mode 100644 examples/chunked_hello_world/README.md create mode 100644 examples/compress_response/README.asciidoc delete mode 100644 examples/compress_response/README.md create mode 100644 examples/cookie/README.asciidoc delete mode 100644 examples/cookie/README.md create mode 100644 examples/echo_get/README.asciidoc delete mode 100644 examples/echo_get/README.md create mode 100644 examples/echo_post/README.asciidoc delete mode 100644 examples/echo_post/README.md create mode 100644 examples/error_hook/README.asciidoc delete mode 100644 examples/error_hook/README.md create mode 100644 examples/eventsource/README.asciidoc delete mode 100644 examples/eventsource/README.md create mode 100644 examples/hello_world/README.asciidoc delete mode 100644 examples/hello_world/README.md create mode 100644 examples/markdown_middleware/README.asciidoc delete mode 100644 examples/markdown_middleware/README.md create mode 100644 examples/rest_basic_auth/README.asciidoc delete mode 100644 examples/rest_basic_auth/README.md create mode 100644 examples/rest_hello_world/README.asciidoc delete mode 100644 examples/rest_hello_world/README.md create mode 100644 examples/rest_pastebin/README.asciidoc delete mode 100644 examples/rest_pastebin/README.md create mode 100644 examples/rest_stream_response/README.asciidoc delete mode 100644 examples/rest_stream_response/README.md create mode 100644 examples/ssl_hello_world/README.asciidoc delete mode 100644 examples/ssl_hello_world/README.md create mode 100644 examples/static_world/README.asciidoc delete mode 100644 examples/static_world/README.md create mode 100644 examples/upload/README.asciidoc delete mode 100644 examples/upload/README.md create mode 100644 examples/web_server/README.asciidoc delete mode 100644 examples/web_server/README.md create mode 100644 examples/websocket/README.asciidoc delete mode 100644 examples/websocket/README.md (limited to 'examples') diff --git a/examples/chunked_hello_world/README.asciidoc b/examples/chunked_hello_world/README.asciidoc new file mode 100644 index 0000000..4b4225d --- /dev/null +++ b/examples/chunked_hello_world/README.asciidoc @@ -0,0 +1,28 @@ += Chunked hello world example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 +or use `curl` to see the chunks arriving one at a time every second. + +== Example output + +[source,bash] +---- +$ time curl -i http://localhost:8080 +HTTP/1.1 200 OK +transfer-encoding: chunked +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:24:16 GMT + +Hello +World +Chunked! +curl -i http://localhost:8080 0.01s user 0.00s system 0% cpu 2.015 total +---- diff --git a/examples/chunked_hello_world/README.md b/examples/chunked_hello_world/README.md deleted file mode 100644 index c568e3b..0000000 --- a/examples/chunked_hello_world/README.md +++ /dev/null @@ -1,36 +0,0 @@ -Chunked hello world example -=========================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/chunked_hello_world_example/bin/chunked_hello_world_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080), -or use `curl` to see the chunks arriving one at a time every second. - -Example output --------------- - -``` bash -$ time curl -i http://localhost:8080 -HTTP/1.1 200 OK -transfer-encoding: chunked -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:24:16 GMT - -Hello -World -Chunked! -curl -i http://localhost:8080 0.01s user 0.00s system 0% cpu 2.015 total -``` diff --git a/examples/compress_response/README.asciidoc b/examples/compress_response/README.asciidoc new file mode 100644 index 0000000..1e6d2ed --- /dev/null +++ b/examples/compress_response/README.asciidoc @@ -0,0 +1,63 @@ += Compressed response example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +== Example output + +Without compression: + +[source,bash] +---- +$ curl -i http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Mon, 07 Jan 2013 18:42:29 GMT +content-length: 909 + +A cowboy is an animal herder who tends cattle on ranches in North America, +traditionally on horseback, and often performs a multitude of other ranch- +related tasks. The historic American cowboy of the late 19th century arose +from the vaquero traditions of northern Mexico and became a figure of special +significance and legend. A subtype, called a wrangler, specifically tends the +horses used to work cattle. In addition to ranch work, some cowboys work for +or participate in rodeos. Cowgirls, first defined as such in the late 19th +century, had a less-well documented historical role, but in the modern world +have established the ability to work at virtually identical tasks and obtained +considerable respect for their achievements. There are also cattle handlers +in many other parts of the world, particularly South America and Australia, +who perform work similar to the cowboy in their respective nations. +---- + +With compression: + +[source,bash] +---- +$ curl -i --compressed http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Mon, 07 Jan 2013 18:42:30 GMT +content-encoding: gzip +content-length: 510 + +A cowboy is an animal herder who tends cattle on ranches in North America, +traditionally on horseback, and often performs a multitude of other ranch- +related tasks. The historic American cowboy of the late 19th century arose +from the vaquero traditions of northern Mexico and became a figure of special +significance and legend. A subtype, called a wrangler, specifically tends the +horses used to work cattle. In addition to ranch work, some cowboys work for +or participate in rodeos. Cowgirls, first defined as such in the late 19th +century, had a less-well documented historical role, but in the modern world +have established the ability to work at virtually identical tasks and obtained +considerable respect for their achievements. There are also cattle handlers +in many other parts of the world, particularly South America and Australia, +who perform work similar to the cowboy in their respective nations. +---- diff --git a/examples/compress_response/README.md b/examples/compress_response/README.md deleted file mode 100644 index ecffcad..0000000 --- a/examples/compress_response/README.md +++ /dev/null @@ -1,70 +0,0 @@ -Compressed response example -=========================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/compress_response_example/bin/compress_response_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- - -Without compression: - -``` bash -$ curl -i http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Mon, 07 Jan 2013 18:42:29 GMT -content-length: 909 - -A cowboy is an animal herder who tends cattle on ranches in North America, -traditionally on horseback, and often performs a multitude of other ranch- -related tasks. The historic American cowboy of the late 19th century arose -from the vaquero traditions of northern Mexico and became a figure of special -significance and legend. A subtype, called a wrangler, specifically tends the -horses used to work cattle. In addition to ranch work, some cowboys work for -or participate in rodeos. Cowgirls, first defined as such in the late 19th -century, had a less-well documented historical role, but in the modern world -have established the ability to work at virtually identical tasks and obtained -considerable respect for their achievements. There are also cattle handlers -in many other parts of the world, particularly South America and Australia, -who perform work similar to the cowboy in their respective nations. -``` - -With compression: - -``` -$ curl -i --compressed http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Mon, 07 Jan 2013 18:42:30 GMT -content-encoding: gzip -content-length: 510 - -A cowboy is an animal herder who tends cattle on ranches in North America, -traditionally on horseback, and often performs a multitude of other ranch- -related tasks. The historic American cowboy of the late 19th century arose -from the vaquero traditions of northern Mexico and became a figure of special -significance and legend. A subtype, called a wrangler, specifically tends the -horses used to work cattle. In addition to ranch work, some cowboys work for -or participate in rodeos. Cowgirls, first defined as such in the late 19th -century, had a less-well documented historical role, but in the modern world -have established the ability to work at virtually identical tasks and obtained -considerable respect for their achievements. There are also cattle handlers -in many other parts of the world, particularly South America and Australia, -who perform work similar to the cowboy in their respective nations. -``` diff --git a/examples/cookie/README.asciidoc b/examples/cookie/README.asciidoc new file mode 100644 index 0000000..20294f5 --- /dev/null +++ b/examples/cookie/README.asciidoc @@ -0,0 +1,13 @@ += Cookie example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +This example allows you to use any path to show that the cookies +are defined site-wide. Try it! diff --git a/examples/cookie/README.md b/examples/cookie/README.md deleted file mode 100644 index 61ddaae..0000000 --- a/examples/cookie/README.md +++ /dev/null @@ -1,20 +0,0 @@ -Cookie example -============== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/cookie_example/bin/cookie_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). -This example allows you to use any path to show that the cookies -are defined site-wide. Try it! diff --git a/examples/echo_get/README.asciidoc b/examples/echo_get/README.asciidoc new file mode 100644 index 0000000..d002d61 --- /dev/null +++ b/examples/echo_get/README.asciidoc @@ -0,0 +1,28 @@ += GET parameter echo example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080/?echo=hello + +You can replace the `echo` parameter with another to check +that the handler is echoing it back properly. + +== Example output + +[source,bash] +---- +$ curl -i "http://localhost:8080/?echo=saymyname" +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:09:04 GMT +content-length: 9 +content-type: text/plain; charset=utf-8 + +saymyname +---- diff --git a/examples/echo_get/README.md b/examples/echo_get/README.md deleted file mode 100644 index 737d04d..0000000 --- a/examples/echo_get/README.md +++ /dev/null @@ -1,36 +0,0 @@ -GET parameter echo example -========================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/echo_get_example/bin/echo_get_example console -``` - -Then point your browser at -[http://localhost:8080/?echo=hello](http://localhost:8080/?echo=hello). -You can replace the `echo` parameter with another to check -that the handler is echoing it back properly. - -Example output --------------- - -``` bash -$ curl -i "http://localhost:8080/?echo=saymyname" -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:09:04 GMT -content-length: 9 -content-type: text/plain; charset=utf-8 - -saymyname -``` diff --git a/examples/echo_post/README.asciidoc b/examples/echo_post/README.asciidoc new file mode 100644 index 0000000..144e216 --- /dev/null +++ b/examples/echo_post/README.asciidoc @@ -0,0 +1,28 @@ += POST parameter echo example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +As this example echoes a POST parameter, it is a little more +complex to test. Some browsers feature tools that allow you +to perform one such request, or you can use the command line +tool `curl` as we will demonstrate. + +== Example output + +[source,bash] +---- +$ curl -i -d echo=echomeplz http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:12:36 GMT +content-length: 9 +content-type: text/plain; charset=utf-8 + +echomeplz +---- diff --git a/examples/echo_post/README.md b/examples/echo_post/README.md deleted file mode 100644 index cc89fd6..0000000 --- a/examples/echo_post/README.md +++ /dev/null @@ -1,36 +0,0 @@ -POST parameter echo example -=========================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/echo_post_example/bin/echo_post_example console -``` - -As this example echoes a POST parameter, it is a little more -complex to test. Some browsers feature tools that allow you -to perform one such request, or you can use the command line -tool `curl` as we will demonstrate. - -Example output --------------- - -``` bash -$ curl -i -d echo=echomeplz http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:12:36 GMT -content-length: 9 -content-type: text/plain; charset=utf-8 - -echomeplz -``` diff --git a/examples/error_hook/README.asciidoc b/examples/error_hook/README.asciidoc new file mode 100644 index 0000000..6f61cb7 --- /dev/null +++ b/examples/error_hook/README.asciidoc @@ -0,0 +1,47 @@ += Error hook example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +== Example output + +Not found: + +[source,bash] +---- +$ curl -i http://localhost:8080 +HTTP/1.1 404 Not Found +connection: keep-alive +server: Cowboy +date: Wed, 27 Feb 2013 23:32:55 GMT +content-length: 56 + +404 Not Found: "/" is not the path you are looking for. +---- + +Bad request: + +[source,bash] +---- +$ telnet localhost 8080 +Trying ::1... +Connection failed: Connection refused +Trying 127.0.0.1... +Connected to localhost. +Escape character is '^]'. +bad +HTTP/1.1 400 Bad Request +connection: close +server: Cowboy +date: Sun, 08 Sep 2013 09:29:27 GMT +content-length: 15 + +HTTP Error 400 +Connection closed by foreign host. +---- diff --git a/examples/error_hook/README.md b/examples/error_hook/README.md deleted file mode 100644 index cd0da97..0000000 --- a/examples/error_hook/README.md +++ /dev/null @@ -1,54 +0,0 @@ -Error hook example -================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/error_hook_example/bin/error_hook_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- - -Not found: - -``` bash -$ curl -i http://localhost:8080 -HTTP/1.1 404 Not Found -connection: keep-alive -server: Cowboy -date: Wed, 27 Feb 2013 23:32:55 GMT -content-length: 56 - -404 Not Found: "/" is not the path you are looking for. -``` - -Bad request: - -``` bash -$ telnet localhost 8080 -Trying ::1... -Connection failed: Connection refused -Trying 127.0.0.1... -Connected to localhost. -Escape character is '^]'. -bad -HTTP/1.1 400 Bad Request -connection: close -server: Cowboy -date: Sun, 08 Sep 2013 09:29:27 GMT -content-length: 15 - -HTTP Error 400 -Connection closed by foreign host. -``` diff --git a/examples/eventsource/README.asciidoc b/examples/eventsource/README.asciidoc new file mode 100644 index 0000000..9461b77 --- /dev/null +++ b/examples/eventsource/README.asciidoc @@ -0,0 +1,10 @@ += EventSource example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 diff --git a/examples/eventsource/README.md b/examples/eventsource/README.md deleted file mode 100644 index b6b611c..0000000 --- a/examples/eventsource/README.md +++ /dev/null @@ -1,19 +0,0 @@ -EventSource example -=================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/eventsource_example/bin/eventsource_example console -``` - -Then point your EventSource capable browser at -[http://localhost:8080](http://localhost:8080). diff --git a/examples/hello_world/README.asciidoc b/examples/hello_world/README.asciidoc new file mode 100644 index 0000000..66a6bd6 --- /dev/null +++ b/examples/hello_world/README.asciidoc @@ -0,0 +1,25 @@ += Hello world example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +== Example output + +[source,bash] +---- +$ curl -i http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:10:25 GMT +content-length: 12 +content-type: text/plain + +Hello world! +---- diff --git a/examples/hello_world/README.md b/examples/hello_world/README.md deleted file mode 100644 index 1e5be0e..0000000 --- a/examples/hello_world/README.md +++ /dev/null @@ -1,33 +0,0 @@ -Hello world example -=================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/hello_world_example/bin/hello_world_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- - -``` bash -$ curl -i http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:10:25 GMT -content-length: 12 -content-type: text/plain - -Hello world! -``` diff --git a/examples/markdown_middleware/README.asciidoc b/examples/markdown_middleware/README.asciidoc new file mode 100644 index 0000000..3881bfb --- /dev/null +++ b/examples/markdown_middleware/README.asciidoc @@ -0,0 +1,15 @@ += Middleware example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080/video.html + +Cowboy will serve all the files you put in the `priv` directory. +If you request a `.html` file that has a corresponding `.md` file +that has been modified more recently than the `.html` file, the +Markdown file will be converted to HTML and served by Cowboy. diff --git a/examples/markdown_middleware/README.md b/examples/markdown_middleware/README.md deleted file mode 100644 index cc890fc..0000000 --- a/examples/markdown_middleware/README.md +++ /dev/null @@ -1,24 +0,0 @@ -Middleware example -================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/markdown_middleware_example/bin/markdown_middleware_example console -``` - -Then point your browser at -[http://localhost:8080/video.html](http://localhost:8080/video.html). - -Cowboy will serve all the files you put in the `priv` directory. -If you request a `.html` file that has a corresponding `.md` file -that has been modified more recently than the `.html` file, the -Markdown file will be converted to HTML and served by Cowboy. diff --git a/examples/rest_basic_auth/README.asciidoc b/examples/rest_basic_auth/README.asciidoc new file mode 100644 index 0000000..04609b3 --- /dev/null +++ b/examples/rest_basic_auth/README.asciidoc @@ -0,0 +1,40 @@ += Basic authorization example using REST + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +== Example output + +Request with no authentication: + +[source,bash] +---- +$ curl -i http://localhost:8080 +HTTP/1.1 401 Unauthorized +connection: keep-alive +server: Cowboy +date: Sun, 20 Jan 2013 14:10:27 GMT +content-length: 0 +www-authenticate: Basic realm="cowboy" +---- + +Request with authentication: + +[source,bash] +---- +$ curl -i -u "Alladin:open sesame" http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Sun, 20 Jan 2013 14:11:12 GMT +content-length: 16 +content-type: text/plain + +Hello, Alladin! +---- diff --git a/examples/rest_basic_auth/README.md b/examples/rest_basic_auth/README.md deleted file mode 100644 index 236ce2f..0000000 --- a/examples/rest_basic_auth/README.md +++ /dev/null @@ -1,47 +0,0 @@ -Basic authorization example using REST -====================================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/rest_basic_auth_example/bin/rest_basic_auth_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- - -Request with no authentication: - -``` bash -$ curl -i http://localhost:8080 -HTTP/1.1 401 Unauthorized -connection: keep-alive -server: Cowboy -date: Sun, 20 Jan 2013 14:10:27 GMT -content-length: 0 -www-authenticate: Basic realm="cowboy" -``` - -Request with authentication: - -``` bash -$ curl -i -u "Alladin:open sesame" http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Sun, 20 Jan 2013 14:11:12 GMT -content-length: 16 -content-type: text/plain - -Hello, Alladin! -``` diff --git a/examples/rest_basic_auth/src/toppage_handler.erl b/examples/rest_basic_auth/src/toppage_handler.erl index 18a8cae..2e8250f 100644 --- a/examples/rest_basic_auth/src/toppage_handler.erl +++ b/examples/rest_basic_auth/src/toppage_handler.erl @@ -13,7 +13,7 @@ init(Req, Opts) -> is_authorized(Req, State) -> case cowboy_req:parse_header(<<"authorization">>, Req) of - {<<"basic">>, {User = <<"Alladin">>, <<"open sesame">>}} -> + {basic, User = <<"Alladin">>, <<"open sesame">>} -> {true, Req, User}; _ -> {{false, <<"Basic realm=\"cowboy\"">>}, Req, State} diff --git a/examples/rest_hello_world/README.asciidoc b/examples/rest_hello_world/README.asciidoc new file mode 100644 index 0000000..5eb94e8 --- /dev/null +++ b/examples/rest_hello_world/README.asciidoc @@ -0,0 +1,81 @@ += REST hello world example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +== Example output + +Request HTML: + +[source,bash] +---- +$ curl -i http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:15:52 GMT +content-length: 136 +content-type: text/html +vary: Accept + + + + + REST Hello World! + + +

REST Hello World as HTML!

+ + +---- + +Request JSON: + +[source,bash] +---- +$ curl -i -H "Accept: application/json" http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:16:46 GMT +content-length: 24 +content-type: application/json +vary: Accept + +{"rest": "Hello World!"} +---- + +Request plain text: + +[source,bash] +---- +$ curl -i -H "Accept: text/plain" http://localhost:8080 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:18:35 GMT +content-length: 25 +content-type: text/plain +vary: Accept + +REST Hello World as text! +---- + +Request a non acceptable content-type: + +[source,bash] +---- +$ curl -i -H "Accept: text/css" http://localhost:8080 +HTTP/1.1 406 Not Acceptable +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:18:51 GMT +content-length: 0 + +---- diff --git a/examples/rest_hello_world/README.md b/examples/rest_hello_world/README.md deleted file mode 100644 index c7e124c..0000000 --- a/examples/rest_hello_world/README.md +++ /dev/null @@ -1,86 +0,0 @@ -REST hello world example -======================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/rest_hello_world_example/bin/rest_hello_world_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Example output --------------- - -Request HTML: - -``` bash -$ curl -i http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:15:52 GMT -content-length: 136 -content-type: text/html -vary: Accept - - - - - REST Hello World! - - -

REST Hello World as HTML!

- - -``` - -Request JSON: - -``` bash -$ curl -i -H "Accept: application/json" http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:16:46 GMT -content-length: 24 -content-type: application/json -vary: Accept - -{"rest": "Hello World!"} -``` - -Request plain text: - -``` bash -$ curl -i -H "Accept: text/plain" http://localhost:8080 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:18:35 GMT -content-length: 25 -content-type: text/plain -vary: Accept - -REST Hello World as text! -``` - -Request a non acceptable content-type: - -``` bash -$ curl -i -H "Accept: text/css" http://localhost:8080 -HTTP/1.1 406 Not Acceptable -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:18:51 GMT -content-length: 0 - -``` diff --git a/examples/rest_pastebin/README.asciidoc b/examples/rest_pastebin/README.asciidoc new file mode 100644 index 0000000..d0cabc1 --- /dev/null +++ b/examples/rest_pastebin/README.asciidoc @@ -0,0 +1,47 @@ += REST pastebin example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +== Usage + +To upload something to the paste application, you can use `curl`: + +[source,bash] +$ | curl -i --data-urlencode paste@- localhost:8080 + +Or, to upload the file `my_file`: + +[source,bash] +curl -i --data-urlencode paste@my_file localhost:8080 + +The URL of your data will be in the location header. Alternately, you can visit +http://localhost:8080 with your favorite web browser and submit your paste via +the form. + +Code that has been pasted can be highlighted with ?lang= option if +you have http://www.andre-simon.de/doku/highlight/en/highlight.html[highlight] +installed (although `pygments` or any other should work just fine). + +This will show the contents of the HTML file: + +[source,bash] +curl -i --data-urlencode paste@priv/index.html localhost:8080 +curl + +If your terminal supports color sequences and `highlight` is installed, +the following command will show the same contents but with HTML syntax +highlighting. + +[source,bash] +curl ?lang=html + +If you open the same URL in your web browser and your web browser tells +Cowboy that it prefers HTML files, you will see the file highlighted +with special HTML markup and CSS. Firefox is known to work. diff --git a/examples/rest_pastebin/README.md b/examples/rest_pastebin/README.md deleted file mode 100644 index a3941f1..0000000 --- a/examples/rest_pastebin/README.md +++ /dev/null @@ -1,60 +0,0 @@ -REST pastebin example -===================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/rest_pastebin_example/bin/rest_pastebin_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -Usage ------ - -To upload something to the paste application, you can use `curl`: - -``` bash -$ | curl -i --data-urlencode paste@- localhost:8080 -``` - -Or, to upload the file `my_file`: - -``` bash -curl -i --data-urlencode paste@my_file localhost:8080 -``` - -The URL of your data will be in the location header. Alternately, you can visit -http://localhost:8080 with your favorite web browser and submit your paste via -the form. - -Code that has been pasted can be highlighted with ?lang= option if -you have [highlight](http://www.andre-simon.de/doku/highlight/en/highlight.html) -installed (although `pygments` or any other should work just fine). - -This will show the contents of the HTML file: - -``` bash -curl -i --data-urlencode paste@priv/index.html localhost:8080 -curl -``` - -If your terminal supports color sequences and `highlight` is installed, -the following command will show the same contents but with HTML syntax -highlighting. - -``` bash -curl ?lang=html -``` - -If you open the same URL in your web browser and your web browser tells -Cowboy that it prefers HTML files, you will see the file highlighted -with special HTML markup and CSS. Firefox is known to work. diff --git a/examples/rest_pastebin/src/toppage_handler.erl b/examples/rest_pastebin/src/toppage_handler.erl index 57b9315..324fa4a 100644 --- a/examples/rest_pastebin/src/toppage_handler.erl +++ b/examples/rest_pastebin/src/toppage_handler.erl @@ -16,7 +16,7 @@ -export([paste_text/2]). init(Req, Opts) -> - random:seed(now()), + random:seed(os:timestamp()), {cowboy_rest, Req, Opts}. allowed_methods(Req, State) -> @@ -57,13 +57,13 @@ create_paste(Req, State) -> paste_html(Req, index) -> {read_file("index.html"), Req, index}; paste_html(Req, Paste) -> - #{lang := Lang} = cowboy_req:match_qs([lang], Req), + #{lang := Lang} = cowboy_req:match_qs([{lang, [], plain}], Req), {format_html(Paste, Lang), Req, Paste}. paste_text(Req, index) -> {read_file("index.txt"), Req, index}; paste_text(Req, Paste) -> - #{lang := Lang} = cowboy_req:match_qs([lang], Req), + #{lang := Lang} = cowboy_req:match_qs([{lang, [], plain}], Req), {format_text(Paste, Lang), Req, Paste}. % Private diff --git a/examples/rest_stream_response/README.asciidoc b/examples/rest_stream_response/README.asciidoc new file mode 100644 index 0000000..411c4c4 --- /dev/null +++ b/examples/rest_stream_response/README.asciidoc @@ -0,0 +1,67 @@ += REST streaming example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +== About + +This example simulates streaming a large amount of data from a data store one +record at a time in CSV format. It also uses a constraint to ensure that the +last segment of the route is an integer. + +== Example output + +Fetch records with the second field with value 1: + +[source,bash] +---- +$ curl -i localhost:8080 +HTTP/1.1 200 OK +transfer-encoding: identity +server: Cowboy +date: Sun, 10 Feb 2013 19:32:16 GMT +connection: close +content-type: text/csv + +DBUZGQ0C,1,28 +BgoQAxMV,1,6 +DAYEFxER,1,18 +... +---- + +Fetch records with the second field with value 4: + +[source,bash] +---- +$ curl -i localhost:8080/4 +HTTP/1.1 200 OK +transfer-encoding: identity +server: Cowboy +date: Sun, 10 Feb 2013 19:34:31 GMT +connection: close +content-type: text/csv + +ABcFDxcE,4,42 +DgYQCgEE,4,5 +CA8BBhYD,4,10 +... +---- + +Fail to use a proper integer and get an error: + +[source,bash] +---- +$ curl -i localhost:8080/foo +HTTP/1.1 404 Not Found +connection: keep-alive +server: Cowboy +date: Sun, 10 Feb 2013 19:36:16 GMT +content-length: 0 + +---- diff --git a/examples/rest_stream_response/README.md b/examples/rest_stream_response/README.md deleted file mode 100644 index 3b49451..0000000 --- a/examples/rest_stream_response/README.md +++ /dev/null @@ -1,74 +0,0 @@ -REST streaming example -====================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/rest_stream_response_example/bin/rest_stream_response_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -About ------ - -This example simulates streaming a large amount of data from a data store one -record at a time in CSV format. It also uses a constraint to ensure that the -last segment of the route is an integer. - -Example output --------------- - -Fetch records with the second field with value 1: - -``` bash -$ curl -i localhost:8080 -HTTP/1.1 200 OK -transfer-encoding: identity -server: Cowboy -date: Sun, 10 Feb 2013 19:32:16 GMT -connection: close -content-type: text/csv - -DBUZGQ0C,1,28 -BgoQAxMV,1,6 -DAYEFxER,1,18 -... -``` - -Fetch records with the second field with value 4: - -``` bash -$ curl -i localhost:8080/4 -HTTP/1.1 200 OK -transfer-encoding: identity -server: Cowboy -date: Sun, 10 Feb 2013 19:34:31 GMT -connection: close -content-type: text/csv - -ABcFDxcE,4,42 -DgYQCgEE,4,5 -CA8BBhYD,4,10 -... -``` - -Fail to use a proper integer and get an error: - -``` bash -$ curl -i localhost:8080/foo -HTTP/1.1 404 Not Found -connection: keep-alive -server: Cowboy -date: Sun, 10 Feb 2013 19:36:16 GMT -content-length: 0 - -``` diff --git a/examples/ssl_hello_world/README.asciidoc b/examples/ssl_hello_world/README.asciidoc new file mode 100644 index 0000000..d3fcf77 --- /dev/null +++ b/examples/ssl_hello_world/README.asciidoc @@ -0,0 +1,27 @@ += Hello world example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to https://localhost:8443 + +You will need to temporarily trust the root certificate authority, +which can also be found in `priv/ssl/cowboy-ca.crt`. + +== Example output + +[source,bash] +---- +$ curl --cacert priv/ssl/cowboy-ca.crt -i https://localhost:8443 +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:10:25 GMT +content-length: 12 + +Hello world! +---- diff --git a/examples/ssl_hello_world/README.md b/examples/ssl_hello_world/README.md deleted file mode 100644 index 1dabbd6..0000000 --- a/examples/ssl_hello_world/README.md +++ /dev/null @@ -1,34 +0,0 @@ -Hello world example -=================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/ssl_hello_world_example/bin/ssl_hello_world_example console -``` - -Then point your browser at [https://localhost:8443](https://localhost:8443). -You will need to temporarily trust the root certificate authority, -which can also be found in `priv/ssl/cowboy-ca.crt`. - -Example output --------------- - -``` bash -$ curl --cacert priv/ssl/cowboy-ca.crt -i https://localhost:8443 -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Fri, 28 Sep 2012 04:10:25 GMT -content-length: 12 - -Hello world! -``` diff --git a/examples/static_world/README.asciidoc b/examples/static_world/README.asciidoc new file mode 100644 index 0000000..3f09900 --- /dev/null +++ b/examples/static_world/README.asciidoc @@ -0,0 +1,30 @@ += Static file handler example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +The example will serve all the files found in the 'priv/' +directory. For example: + +* http://localhost:8080/test.txt[Plain text file] +* http://localhost:8080/video.html[HTML5 video demo] + +== Example output + +[source,bash] +---- +$ curl -i http://localhost:8080/test.txt +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Mon, 09 Sep 2013 13:49:50 GMT +content-length: 52 +content-type: text/plain +last-modified: Fri, 18 Jan 2013 16:33:31 GMT + +If you read this then the static file server works! +---- diff --git a/examples/static_world/README.md b/examples/static_world/README.md deleted file mode 100644 index aa72e89..0000000 --- a/examples/static_world/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Static file handler example -=========================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/static_world_example/bin/static_world_example console -``` - -The example will serve all the files found in the `priv` -directory. For example: - - * [Plain text file](http://localhost:8080/test.txt) - * [HTML5 video demo](http://localhost:8080/video.html) - -Example output --------------- - -``` bash -$ curl -i http://localhost:8080/test.txt -HTTP/1.1 200 OK -connection: keep-alive -server: Cowboy -date: Mon, 09 Sep 2013 13:49:50 GMT -content-length: 52 -content-type: text/plain -last-modified: Fri, 18 Jan 2013 16:33:31 GMT - -If you read this then the static file server works! -``` diff --git a/examples/upload/README.asciidoc b/examples/upload/README.asciidoc new file mode 100644 index 0000000..96f6ec7 --- /dev/null +++ b/examples/upload/README.asciidoc @@ -0,0 +1,12 @@ += Multipart upload example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 + +The uploaded file will be displayed in the shell directly. diff --git a/examples/upload/README.md b/examples/upload/README.md deleted file mode 100644 index 0a0d8b4..0000000 --- a/examples/upload/README.md +++ /dev/null @@ -1,20 +0,0 @@ -Multipart upload example -======================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/upload_example/bin/upload_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). - -The uploaded file will be displayed in the shell directly. diff --git a/examples/web_server/README.asciidoc b/examples/web_server/README.asciidoc new file mode 100644 index 0000000..8f0eb4b --- /dev/null +++ b/examples/web_server/README.asciidoc @@ -0,0 +1,11 @@ += Directory indexing example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 +to browse the contents of the `priv` directory. diff --git a/examples/web_server/README.md b/examples/web_server/README.md deleted file mode 100644 index b8938dd..0000000 --- a/examples/web_server/README.md +++ /dev/null @@ -1,19 +0,0 @@ -Static file handler example -=========================== - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/web_server_example/bin/web_server_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080) -to browse the contents of the `priv` directory. diff --git a/examples/websocket/README.asciidoc b/examples/websocket/README.asciidoc new file mode 100644 index 0000000..0b22607 --- /dev/null +++ b/examples/websocket/README.asciidoc @@ -0,0 +1,10 @@ += Websocket example + +To try this example, you need GNU `make` and `git` in your PATH. + +To build and run the example, use the following command: + +[source,bash] +$ make run + +Then point your browser to http://localhost:8080 diff --git a/examples/websocket/README.md b/examples/websocket/README.md deleted file mode 100644 index bb55c1c..0000000 --- a/examples/websocket/README.md +++ /dev/null @@ -1,18 +0,0 @@ -Websocket example -================= - -To try this example, you need GNU `make` and `git` in your PATH. - -To build the example, run the following command: - -``` bash -$ make -``` - -To start the release in the foreground: - -``` bash -$ ./_rel/websocket_example/bin/websocket_example console -``` - -Then point your browser at [http://localhost:8080](http://localhost:8080). -- cgit v1.2.3