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:
parent
ecb234693c
commit
b69903435e
8 changed files with 112 additions and 0 deletions
13
examples/elixir_hello_world/lib/elixir_hello_world.ex
Normal file
13
examples/elixir_hello_world/lib/elixir_hello_world.ex
Normal 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
|
|
@ -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
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue