aboutsummaryrefslogtreecommitdiffstats
path: root/examples/elixir_hello_world
diff options
context:
space:
mode:
authorYurii Rashkovskii <[email protected]>2013-01-29 10:18:52 -0800
committerJosé Valim <[email protected]>2013-02-06 14:08:49 -0700
commitb69903435e0278a6a91749d729f08ac01a8f623a (patch)
treeec5ea1c7304ee50c3ab9b490ca7f0af6ebbe33d3 /examples/elixir_hello_world
parentecb234693c82553261738c28f883b327a2d586e1 (diff)
downloadcowboy-b69903435e0278a6a91749d729f08ac01a8f623a.tar.gz
cowboy-b69903435e0278a6a91749d729f08ac01a8f623a.tar.bz2
cowboy-b69903435e0278a6a91749d729f08ac01a8f623a.zip
Elixir hello world example
Diffstat (limited to 'examples/elixir_hello_world')
-rw-r--r--examples/elixir_hello_world/README.md42
-rw-r--r--examples/elixir_hello_world/lib/elixir_hello_world.ex13
-rw-r--r--examples/elixir_hello_world/lib/elixir_hello_world/supervisor.ex12
-rw-r--r--examples/elixir_hello_world/lib/elixir_hello_world/top_page_handler.ex12
-rw-r--r--examples/elixir_hello_world/mix.exs20
-rw-r--r--examples/elixir_hello_world/test/elixir_hello_world_test.exs9
-rw-r--r--examples/elixir_hello_world/test/test_helper.exs1
7 files changed, 109 insertions, 0 deletions
diff --git a/examples/elixir_hello_world/README.md b/examples/elixir_hello_world/README.md
new file mode 100644
index 0000000..09fef39
--- /dev/null
+++ b/examples/elixir_hello_world/README.md
@@ -0,0 +1,42 @@
+Elixir Hello World
+==================
+
+This is an example of running Cowboy with [Elixir](http://elixir-lang.org).
+
+You need Elixir installed
+([instructions here](http://elixir-lang.org/getting_started/1.html))
+to run this example. After installing Elixir, you should have both
+`elixir` and `mix` executables available.
+
+You also need [rebar](https://github.com/rebar/rebar) in your PATH
+to compile dependencies.
+
+Then type the following command:
+
+```
+mix deps.get
+```
+
+The command above will fetch all dependencies and compile them.
+
+You can then start the Erlang node with the following command:
+
+```
+mix run --no-halt
+```
+
+Then point your browser to localhost:8080.
+
+Example
+-------
+
+``` bash
+$ curl -i http://localhost:8080
+HTTP/1.1 200 OK
+connection: keep-alive
+server: Cowboy
+date: Fri, 28 Sep 2012 04:10:25 GMT
+content-length: 12
+
+Hello world!
+```
diff --git a/examples/elixir_hello_world/lib/elixir_hello_world.ex b/examples/elixir_hello_world/lib/elixir_hello_world.ex
new file mode 100644
index 0000000..2da484b
--- /dev/null
+++ b/examples/elixir_hello_world/lib/elixir_hello_world.ex
@@ -0,0 +1,13 @@
+defmodule ElixirHelloWorld do
+ use Application.Behaviour
+
+ def start(_type, _args) do
+ dispatch = :cowboy_router.compile([
+ {:_, [{"/", ElixirHelloWorld.TopPageHandler, []}]}
+ ])
+ {:ok, _} = :cowboy.start_http(:http, 100,
+ [port: 8080],
+ [env: [dispatch: dispatch]])
+ ElixirHelloWorld.Supervisor.start_link
+ end
+end
diff --git a/examples/elixir_hello_world/lib/elixir_hello_world/supervisor.ex b/examples/elixir_hello_world/lib/elixir_hello_world/supervisor.ex
new file mode 100644
index 0000000..f9b569f
--- /dev/null
+++ b/examples/elixir_hello_world/lib/elixir_hello_world/supervisor.ex
@@ -0,0 +1,12 @@
+defmodule ElixirHelloWorld.Supervisor do
+ use Supervisor.Behaviour
+
+ def start_link do
+ :supervisor.start_link(__MODULE__, [])
+ end
+
+ def init([]) do
+ children = []
+ supervise children, strategy: :one_for_one
+ end
+end
diff --git a/examples/elixir_hello_world/lib/elixir_hello_world/top_page_handler.ex b/examples/elixir_hello_world/lib/elixir_hello_world/top_page_handler.ex
new file mode 100644
index 0000000..58e37b4
--- /dev/null
+++ b/examples/elixir_hello_world/lib/elixir_hello_world/top_page_handler.ex
@@ -0,0 +1,12 @@
+defmodule ElixirHelloWorld.TopPageHandler do
+ def init(_transport, req, []) do
+ {:ok, req, nil}
+ end
+
+ def handle(req, state) do
+ {:ok, req} = :cowboy_req.reply(200, [], "Hello world!", req)
+ {:ok, req, state}
+ end
+
+ def terminate(_reason, _req, _state), do: :ok
+end
diff --git a/examples/elixir_hello_world/mix.exs b/examples/elixir_hello_world/mix.exs
new file mode 100644
index 0000000..862c6fa
--- /dev/null
+++ b/examples/elixir_hello_world/mix.exs
@@ -0,0 +1,20 @@
+defmodule ElixirHelloWorld.Mixfile do
+ use Mix.Project
+
+ def project do
+ [ app: :elixir_hello_world,
+ version: "0.0.1",
+ deps: deps ]
+ end
+
+ # Configuration for the OTP application
+ def application do
+ [ mod: { ElixirHelloWorld, [] },
+ applications: [:cowboy] ]
+ end
+
+ defp deps do
+ [ {:ranch, github: "extend/ranch", tag: "0.6.1"},
+ {:cowboy, github: "extend/cowboy"} ]
+ end
+end
diff --git a/examples/elixir_hello_world/test/elixir_hello_world_test.exs b/examples/elixir_hello_world/test/elixir_hello_world_test.exs
new file mode 100644
index 0000000..2c14d6c
--- /dev/null
+++ b/examples/elixir_hello_world/test/elixir_hello_world_test.exs
@@ -0,0 +1,9 @@
+Code.require_file "../test_helper.exs", __FILE__
+
+defmodule ElixirHelloWorldTest do
+ use ExUnit.Case
+
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/examples/elixir_hello_world/test/test_helper.exs b/examples/elixir_hello_world/test/test_helper.exs
new file mode 100644
index 0000000..4b8b246
--- /dev/null
+++ b/examples/elixir_hello_world/test/test_helper.exs
@@ -0,0 +1 @@
+ExUnit.start