Просмотр исходного кода

Convert the POST echo example to a release

Loïc Hoguin 11 лет назад
Родитель
Сommit
57e6d1f416

+ 14 - 0
examples/echo_post/Makefile

@@ -0,0 +1,14 @@
+PROJECT = echo_post
+
+DEPS = cowboy
+dep_cowboy = pkg://cowboy master
+
+.PHONY: release clean-release
+
+release: clean-release all
+	relx
+
+clean-release:
+	rm -rf _rel
+
+include ../../erlang.mk

+ 18 - 20
examples/echo_post/README.md

@@ -1,30 +1,28 @@
-Cowboy POST Echo
-================
+POST parameter echo 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:
-```
-./start.sh
+``` bash
+$ make
 ```
 
-Then point your browser to the indicated URL. You can change
-the GET parameter to check that the handler is echoing properly.
+To start the release in the foreground:
 
-Then run the following command, replacing STRING_TO_ECHO by the
-string you want to echo. Check the ```curl_post.sh``` file for details.
-
-```
-./curl_post.sh STRING_TO_ECHO
+``` bash
+$ ./_rel/bin/echo_post_example console
 ```
 
-Example
--------
+As this example echoes a POST parameter, it is a little more
+complex to test. Some browsers feature tools that allow you
+to perform one such request, or you can use the command line
+tool `curl` as we will demonstrate.
+
+Example output
+--------------
 
 ``` bash
 $ curl -i -d echo=echomeplz http://localhost:8080
@@ -33,7 +31,7 @@ connection: keep-alive
 server: Cowboy
 date: Fri, 28 Sep 2012 04:12:36 GMT
 content-length: 9
-Content-Encoding: utf-8
+content-type: text/plain; charset=utf-8
 
 echomeplz
 ```

+ 0 - 2
examples/echo_post/curl_post.sh

@@ -1,2 +0,0 @@
-#!/bin/sh
-curl -i -d echo=$1 http://localhost:8080

+ 0 - 4
examples/echo_post/rebar.config

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

+ 2 - 0
examples/echo_post/relx.config

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

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

@@ -1,15 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(echo_post).
-
-%% 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(echo_post).

+ 0 - 3
examples/echo_post/start.sh

@@ -1,3 +0,0 @@
-#!/bin/sh
-erl -pa ebin deps/*/ebin -s echo_post \
-	-eval "io:format(\"Run ./curl_post.sh STRING_TO_ECHO~n\")."