0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 12:40:25 +00:00

Elixir hello world example

This commit is contained in:
Yurii Rashkovskii 2013-01-29 10:18:52 -08:00 committed by José Valim
parent ecb234693c
commit b69903435e
8 changed files with 112 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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