aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJosh Toft <[email protected]>2012-09-27 21:32:11 -0700
committerJosh Toft <[email protected]>2012-10-01 10:37:24 -0700
commit855828d15cdeea343ba499071c14caaeeec19dab (patch)
treecfce1e77220417aee439aa95412fa0e59b7fe452 /examples
parent0b82eebed654bd894802acb52697a4d4187cb228 (diff)
downloadcowboy-855828d15cdeea343ba499071c14caaeeec19dab.tar.gz
cowboy-855828d15cdeea343ba499071c14caaeeec19dab.tar.bz2
cowboy-855828d15cdeea343ba499071c14caaeeec19dab.zip
Make example README's more thorough
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md15
-rw-r--r--examples/chunked_hello_world/README.md21
-rw-r--r--examples/echo_get/README.md15
-rw-r--r--examples/echo_post/README.md15
-rw-r--r--examples/hello_world/README.md14
-rw-r--r--examples/rest_hello_world/README.md71
-rw-r--r--examples/static/README.md26
7 files changed, 171 insertions, 6 deletions
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
+
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>REST Hello World!</title>
+</head>
+<body>
+ <p>REST Hello World as HTML!</p>
+</body>
+</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!
+```