Browse Source

Convert the REST hello world example to a release

Loïc Hoguin 11 years ago
parent
commit
81843414b0

+ 14 - 0
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

+ 26 - 22
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
@@ -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>
@@ -41,7 +44,7 @@ Vary: Accept
 </html>
 ```
 
-### Get JSON
+Request JSON:
 
 ``` bash
 $ curl -i -H "Accept: application/json" http://localhost:8080
@@ -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
@@ -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

+ 0 - 4
examples/rest_hello_world/rebar.config

@@ -1,4 +0,0 @@
-{deps, [
-	{cowboy, ".*",
-		{git, "git://github.com/extend/cowboy.git", "master"}}
-]}.

+ 2 - 0
examples/rest_hello_world/relx.config

@@ -0,0 +1,2 @@
+{release, {rest_hello_world_example, "1"}, [rest_hello_world]}.
+{extended_start_script, true}.

+ 0 - 15
examples/rest_hello_world/src/rest_hello_world.erl

@@ -1,15 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(rest_hello_world).
-
-%% API.
--export([start/0]).
-
-%% API.
-
-start() ->
-	ok = application:start(crypto),
-	ok = application:start(cowlib),
-	ok = application:start(ranch),
-	ok = application:start(cowboy),
-	ok = application:start(rest_hello_world).

+ 0 - 6
examples/rest_hello_world/start.sh

@@ -1,6 +0,0 @@
-#!/bin/sh
-erl -pa ebin deps/*/ebin -s rest_hello_world \
-	-eval "io:format(\"Get HTML: curl -i http://localhost:8080~n\")." \
-	-eval "io:format(\"Get JSON: curl -i -H \\\"Accept: application/json\\\" http://localhost:8080~n\")." \
-	-eval "io:format(\"Get text: curl -i -H \\\"Accept: text/plain\\\" http://localhost:8080~n\")." \
-	-eval "io:format(\"Get a 406: curl -i -H \\\"Accept: text/css\\\" http://localhost:8080~n\")."