From 855828d15cdeea343ba499071c14caaeeec19dab Mon Sep 17 00:00:00 2001 From: Josh Toft Date: Thu, 27 Sep 2012 21:32:11 -0700 Subject: Make example README's more thorough --- examples/README.md | 15 ++++++- examples/chunked_hello_world/README.md | 21 +++++++++- examples/echo_get/README.md | 15 +++++++ examples/echo_post/README.md | 15 +++++++ examples/hello_world/README.md | 14 +++++++ examples/rest_hello_world/README.md | 71 +++++++++++++++++++++++++++++++++- examples/static/README.md | 26 +++++++++++++ 7 files changed, 171 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/README.md b/examples/README.md index dc88057..e4253cb 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,17 @@ Cowboy examples =============== -The Cowboy examples can be found in a separate repository: +* [hello_world](./hello_world): +simplest example application -* https://github.com/extend/cowboy_examples +* [echo_get](./echo_get): +parse and echo a GET query string + +* [echo_post](./echo_post): +parse and echo a POST parameter + +* [chunked_hello_world](./chunked_hello_world): +demonstrates chunked data transfer with two one-second delays + +* [static](./static): +an example file server diff --git a/examples/chunked_hello_world/README.md b/examples/chunked_hello_world/README.md index decf50f..be8f046 100644 --- a/examples/chunked_hello_world/README.md +++ b/examples/chunked_hello_world/README.md @@ -1,5 +1,5 @@ -Cowboy Hello World -================== +Cowboy Chunked Hello World +========================== To compile this example you need rebar in your PATH. @@ -14,3 +14,20 @@ You can then start the Erlang node with the following command: ``` Then run the given command or point your browser to the indicated URL. + +Example +------- + +```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/echo_get/README.md b/examples/echo_get/README.md index 9a09ca1..233ae05 100644 --- a/examples/echo_get/README.md +++ b/examples/echo_get/README.md @@ -15,3 +15,18 @@ You can then start the Erlang node with the following command: Then point your browser to the indicated URL. You can change the GET parameter to check that the handler is echoing properly. + +Example +------- + +``` 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-Encoding: utf-8 + +saymyname +``` diff --git a/examples/echo_post/README.md b/examples/echo_post/README.md index dcfa913..66b7ee5 100644 --- a/examples/echo_post/README.md +++ b/examples/echo_post/README.md @@ -22,3 +22,18 @@ string you want to echo. Check the ```curl_post.sh``` file for details. ``` ./curl_post.sh STRING_TO_ECHO ``` + +Example +------- + +``` 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-Encoding: utf-8 + +echomeplz +``` diff --git a/examples/hello_world/README.md b/examples/hello_world/README.md index 71b7983..dd3d948 100644 --- a/examples/hello_world/README.md +++ b/examples/hello_world/README.md @@ -14,3 +14,17 @@ You can then start the Erlang node with the following command: ``` Then point your browser to the indicated URL. + +Example +------- + +``` 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 + +Hello world! +``` diff --git a/examples/rest_hello_world/README.md b/examples/rest_hello_world/README.md index 6b62bd7..c0b8c8d 100644 --- a/examples/rest_hello_world/README.md +++ b/examples/rest_hello_world/README.md @@ -1,5 +1,5 @@ -Cowboy Hello World -================== +Cowboy Rest Hello World +======================= To compile this example you need rebar in your PATH. @@ -14,3 +14,70 @@ You can then start the Erlang node with the following command: ``` Then run any given command or point your browser to the indicated URL. + +Examples +-------- + +### Get 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 +Variances: Accept + + + + + REST Hello World! + + +

REST Hello World as HTML!

+ + +``` + +### Get 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 +Variances: Accept + +{"rest": "Hello World!"} +``` + +### Get 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 +Variances: Accept + +REST Hello World as text! +``` + +### Get a 406 +``` 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/static/README.md b/examples/static/README.md index a9b9f5b..ef46312 100644 --- a/examples/static/README.md +++ b/examples/static/README.md @@ -16,3 +16,29 @@ You can then start the Erlang node with the following command: Cowboy will serve all the files you put in the priv/ directory. You can replace the filename given in the example URL with the one of a file you added to this directory to receive that file. + +Example +------- + +Show that the file is returned as an octet-stream + +``` bash +$ curl -i http://localhost:8080/test.txt +HTTP/1.1 200 OK +connection: keep-alive +server: Cowboy +date: Fri, 28 Sep 2012 04:19:40 GMT +content-length: 52 +Content-Type: application/octet-stream +Last-Modified: Fri, 28 Sep 2012 04:01:20 GMT + +If you read this then the static file server works! +``` + +Finally download and cat the file to verify + +``` bash +$ curl -sLO http://localhost:8080/test.txt +$ cat test.txt +If you read this then the static file server works! +``` -- cgit v1.2.3