Skip to content

Commit

Permalink
Convert the REST hello world example to a release
Browse files Browse the repository at this point in the history
  • Loading branch information
essen committed Sep 8, 2013
1 parent 49acfce commit 8184341
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 47 deletions.
14 changes: 14 additions & 0 deletions examples/rest_hello_world/Makefile
@@ -0,0 +1,14 @@
PROJECT = rest_hello_world

DEPS = cowboy
dep_cowboy = pkg://cowboy master

.PHONY: release clean-release

release: clean-release all
relx

clean-release:
rm -rf _rel

include ../../erlang.mk
48 changes: 26 additions & 22 deletions examples/rest_hello_world/README.md
@@ -1,24 +1,27 @@
Cowboy Rest Hello World
=======================
REST hello world example
========================

To compile this example you need rebar in your PATH.
To try this example, you need GNU `make`, `git` and
[relx](https://github.com/erlware/relx) in your PATH.

Type the following command:
```
$ rebar get-deps compile
```
To build the example, run the following command:

You can then start the Erlang node with the following command:
``` bash
$ make
```
./start.sh

To start the release in the foreground:

``` bash
$ ./_rel/bin/hello_world_example console
```

Then run any given command or point your browser to the indicated URL.
Then point your browser at [http://localhost:8080](http://localhost:8080).

Examples
--------
Example output
--------------

### Get HTML
Request HTML:

``` bash
$ curl -i http://localhost:8080
Expand All @@ -27,8 +30,8 @@ connection: keep-alive
server: Cowboy
date: Fri, 28 Sep 2012 04:15:52 GMT
content-length: 136
Content-Type: text/html
Vary: Accept
content-type: text/html
vary: Accept

<html>
<head>
Expand All @@ -41,7 +44,7 @@ Vary: Accept
</html>
```

### Get JSON
Request JSON:

``` bash
$ curl -i -H "Accept: application/json" http://localhost:8080
Expand All @@ -50,13 +53,13 @@ connection: keep-alive
server: Cowboy
date: Fri, 28 Sep 2012 04:16:46 GMT
content-length: 24
Content-Type: application/json
Vary: Accept
content-type: application/json
vary: Accept

{"rest": "Hello World!"}
```

### Get text
Request plain text:

``` bash
$ curl -i -H "Accept: text/plain" http://localhost:8080
Expand All @@ -65,13 +68,14 @@ connection: keep-alive
server: Cowboy
date: Fri, 28 Sep 2012 04:18:35 GMT
content-length: 25
Content-Type: text/plain
Vary: Accept
content-type: text/plain
vary: Accept

REST Hello World as text!
```

### Get a 406
Request a non acceptable content-type:

``` bash
$ curl -i -H "Accept: text/css" http://localhost:8080
HTTP/1.1 406 Not Acceptable
Expand Down
4 changes: 0 additions & 4 deletions examples/rest_hello_world/rebar.config

This file was deleted.

2 changes: 2 additions & 0 deletions examples/rest_hello_world/relx.config
@@ -0,0 +1,2 @@
{release, {rest_hello_world_example, "1"}, [rest_hello_world]}.
{extended_start_script, true}.
15 changes: 0 additions & 15 deletions examples/rest_hello_world/src/rest_hello_world.erl

This file was deleted.

6 changes: 0 additions & 6 deletions examples/rest_hello_world/start.sh

This file was deleted.

0 comments on commit 8184341

Please sign in to comment.