mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Make example README's more thorough
This commit is contained in:
parent
0b82eebed6
commit
855828d15c
7 changed files with 171 additions and 6 deletions
|
@ -1,6 +1,17 @@
|
||||||
Cowboy examples
|
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
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Cowboy Hello World
|
Cowboy Chunked Hello World
|
||||||
==================
|
==========================
|
||||||
|
|
||||||
To compile this example you need rebar in your PATH.
|
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.
|
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,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
|
Then point your browser to the indicated URL. You can change
|
||||||
the GET parameter to check that the handler is echoing properly.
|
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
|
||||||
|
```
|
||||||
|
|
|
@ -22,3 +22,18 @@ string you want to echo. Check the ```curl_post.sh``` file for details.
|
||||||
```
|
```
|
||||||
./curl_post.sh STRING_TO_ECHO
|
./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,3 +14,17 @@ You can then start the Erlang node with the following command:
|
||||||
```
|
```
|
||||||
|
|
||||||
Then point your browser to the indicated URL.
|
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!
|
||||||
|
```
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Cowboy Hello World
|
Cowboy Rest Hello World
|
||||||
==================
|
=======================
|
||||||
|
|
||||||
To compile this example you need rebar in your PATH.
|
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.
|
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
|
||||||
|
|
||||||
|
```
|
||||||
|
|
|
@ -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.
|
Cowboy will serve all the files you put in the priv/ directory.
|
||||||
You can replace the filename given in the example URL with the
|
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.
|
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!
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue