Skip to content

Instantly share code, notes, and snippets.

@sascha
Created August 10, 2015 09:23
Show Gist options
  • Save sascha/d98e5ceb3c3003334d98 to your computer and use it in GitHub Desktop.
Save sascha/d98e5ceb3c3003334d98 to your computer and use it in GitHub Desktop.
defmodule Handler do
def init(_type, req, []) do
{:ok, req, :no_state}
end
def handle(request, state) do
{ :ok, reply } = :cowboy_req.reply(
200,
[ {"content-type", "text/plain"} ],
"Hello World",
request
)
{:ok, reply, state}
end
def terminate(_reason, _request, _state) do
:ok
end
end
defmodule HelloWorld do
def start(_type, _args) do
dispatch = :cowboy_router.compile([
{ :_,
[
{"/", Handler, []}
]
}
])
{ :ok, _ } = :cowboy.start_http(:http, 100, [{:port, 8080}], [{ :env, [{:dispatch, dispatch}]}])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment