Skip to content

Commit

Permalink
Convert the GET echo example to a release
Browse files Browse the repository at this point in the history
  • Loading branch information
essen committed Sep 7, 2013
1 parent 340f0a5 commit e2b11bb
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
14 changes: 14 additions & 0 deletions examples/echo_get/Makefile
Original file line number Diff line number Diff line change
@@ -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
33 changes: 19 additions & 14 deletions examples/echo_get/README.md
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
```
4 changes: 0 additions & 4 deletions examples/echo_get/rebar.config

This file was deleted.

2 changes: 2 additions & 0 deletions examples/echo_get/relx.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{release, {echo_get_example, "1"}, [echo_get]}.
{extended_start_script, true}.
15 changes: 0 additions & 15 deletions examples/echo_get/src/echo_get.erl

This file was deleted.

5 changes: 3 additions & 2 deletions examples/echo_get/src/toppage_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 0 additions & 3 deletions examples/echo_get/start.sh

This file was deleted.

0 comments on commit e2b11bb

Please sign in to comment.