diff options
author | Loïc Hoguin <[email protected]> | 2013-09-07 22:26:40 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-09-07 22:26:40 +0200 |
commit | e2b11bbeedc0f7114910bb04bcb842d25e789427 (patch) | |
tree | d0e00d9758a04ea9f88b9357d07d9f0da768947b /examples/echo_get | |
parent | 340f0a51123b476bca765b87d3f36411e896b5e3 (diff) | |
download | cowboy-e2b11bbeedc0f7114910bb04bcb842d25e789427.tar.gz cowboy-e2b11bbeedc0f7114910bb04bcb842d25e789427.tar.bz2 cowboy-e2b11bbeedc0f7114910bb04bcb842d25e789427.zip |
Convert the GET echo example to a release
Diffstat (limited to 'examples/echo_get')
-rw-r--r-- | examples/echo_get/Makefile | 14 | ||||
-rw-r--r-- | examples/echo_get/README.md | 33 | ||||
-rw-r--r-- | examples/echo_get/rebar.config | 4 | ||||
-rw-r--r-- | examples/echo_get/relx.config | 2 | ||||
-rw-r--r-- | examples/echo_get/src/echo_get.erl | 15 | ||||
-rw-r--r-- | examples/echo_get/src/toppage_handler.erl | 5 | ||||
-rwxr-xr-x | examples/echo_get/start.sh | 3 |
7 files changed, 38 insertions, 38 deletions
diff --git a/examples/echo_get/Makefile b/examples/echo_get/Makefile new file mode 100644 index 0000000..76c9f7b --- /dev/null +++ b/examples/echo_get/Makefile @@ -0,0 +1,14 @@ +PROJECT = echo_get + +DEPS = cowboy +dep_cowboy = pkg://cowboy master + +.PHONY: release clean-release + +release: clean-release all + relx + +clean-release: + rm -rf _rel + +include ../../erlang.mk diff --git a/examples/echo_get/README.md b/examples/echo_get/README.md index 233ae05..28f9d0c 100644 --- a/examples/echo_get/README.md +++ b/examples/echo_get/README.md @@ -1,23 +1,28 @@ -Cowboy GET Echo -=============== +GET 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: +``` bash +$ make ``` -./start.sh + +To start the release in the foreground: + +``` bash +$ ./_rel/bin/get_echo_example console ``` -Then point your browser to the indicated URL. You can change -the GET parameter to check that the handler is echoing properly. +Then point your browser at +[http://localhost:8080/?echo=hello](http://localhost:8080/?echo=hello). +You can replace the `echo` parameter with another to check +that the handler is echoing it back properly. -Example -------- +Example output +-------------- ``` bash $ curl -i "http://localhost:8080/?echo=saymyname" @@ -26,7 +31,7 @@ connection: keep-alive server: Cowboy date: Fri, 28 Sep 2012 04:09:04 GMT content-length: 9 -Content-Encoding: utf-8 +content-type: text/plain; charset=utf-8 saymyname ``` diff --git a/examples/echo_get/rebar.config b/examples/echo_get/rebar.config deleted file mode 100644 index 6ad3062..0000000 --- a/examples/echo_get/rebar.config +++ /dev/null @@ -1,4 +0,0 @@ -{deps, [ - {cowboy, ".*", - {git, "git://github.com/extend/cowboy.git", "master"}} -]}. diff --git a/examples/echo_get/relx.config b/examples/echo_get/relx.config new file mode 100644 index 0000000..fdf4144 --- /dev/null +++ b/examples/echo_get/relx.config @@ -0,0 +1,2 @@ +{release, {echo_get_example, "1"}, [echo_get]}. +{extended_start_script, true}. diff --git a/examples/echo_get/src/echo_get.erl b/examples/echo_get/src/echo_get.erl deleted file mode 100644 index 9b1307d..0000000 --- a/examples/echo_get/src/echo_get.erl +++ /dev/null @@ -1,15 +0,0 @@ -%% Feel free to use, reuse and abuse the code in this file. - --module(echo_get). - -%% 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_get). diff --git a/examples/echo_get/src/toppage_handler.erl b/examples/echo_get/src/toppage_handler.erl index c604bae..1187dc6 100644 --- a/examples/echo_get/src/toppage_handler.erl +++ b/examples/echo_get/src/toppage_handler.erl @@ -19,8 +19,9 @@ handle(Req, State) -> echo(<<"GET">>, undefined, Req) -> cowboy_req:reply(400, [], <<"Missing echo parameter.">>, Req); echo(<<"GET">>, Echo, Req) -> - cowboy_req:reply(200, - [{<<"content-encoding">>, <<"utf-8">>}], Echo, Req); + cowboy_req:reply(200, [ + {<<"content-type">>, <<"text/plain; charset=utf-8">>} + ], Echo, Req); echo(_, _, Req) -> %% Method not allowed. cowboy_req:reply(405, Req). diff --git a/examples/echo_get/start.sh b/examples/echo_get/start.sh deleted file mode 100755 index 4704feb..0000000 --- a/examples/echo_get/start.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -erl -pa ebin deps/*/ebin -s echo_get \ - -eval "io:format(\"Point your browser at http://localhost:8080/?echo=test~n\")." |