Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing recursive examples README #269

Merged
merged 1 commit into from Oct 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions 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
21 changes: 19 additions & 2 deletions 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.

Expand All @@ -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
```
15 changes: 15 additions & 0 deletions examples/echo_get/README.md
Expand Up @@ -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
```
15 changes: 15 additions & 0 deletions examples/echo_post/README.md
Expand Up @@ -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
```
14 changes: 14 additions & 0 deletions examples/hello_world/README.md
Expand Up @@ -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!
```
71 changes: 69 additions & 2 deletions 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.

Expand All @@ -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

```
26 changes: 26 additions & 0 deletions examples/static/README.md
Expand Up @@ -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!
```