mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Convert the POST echo example to a release
This commit is contained in:
parent
e2b11bbeed
commit
57e6d1f416
7 changed files with 35 additions and 45 deletions
14
examples/echo_post/Makefile
Normal file
14
examples/echo_post/Makefile
Normal file
|
@ -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
|
|
@ -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:
|
||||
|
||||
``` bash
|
||||
$ make
|
||||
```
|
||||
|
||||
You can then start the Erlang node with the following command:
|
||||
```
|
||||
./start.sh
|
||||
To start the release in the foreground:
|
||||
|
||||
``` bash
|
||||
$ ./_rel/bin/echo_post_example console
|
||||
```
|
||||
|
||||
Then point your browser to the indicated URL. You can change
|
||||
the GET parameter to check that the handler is echoing properly.
|
||||
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.
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
Example
|
||||
-------
|
||||
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
|
||||
```
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/sh
|
||||
curl -i -d echo=$1 http://localhost:8080
|
|
@ -1,4 +0,0 @@
|
|||
{deps, [
|
||||
{cowboy, ".*",
|
||||
{git, "git://github.com/extend/cowboy.git", "master"}}
|
||||
]}.
|
2
examples/echo_post/relx.config
Normal file
2
examples/echo_post/relx.config
Normal file
|
@ -0,0 +1,2 @@
|
|||
{release, {echo_post_example, "1"}, [echo_post]}.
|
||||
{extended_start_script, true}.
|
|
@ -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).
|
|
@ -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\")."
|
Loading…
Add table
Add a link
Reference in a new issue