|
@@ -1,19 +1,13 @@
|
|
|
defmodule Hello do
|
|
|
-
|
|
|
def start(_type, _args) do
|
|
|
dispatch = :cowboy_router.compile([
|
|
|
-
|
|
|
- { :_,
|
|
|
- [
|
|
|
- {"/json", JsonHandler, []},
|
|
|
- {"/plaintext", PlaintextHandler, []}
|
|
|
- ]}
|
|
|
+ {:_, [{"/json", JsonHandler, []},
|
|
|
+ {"/plaintext", PlaintextHandler, []}]}
|
|
|
])
|
|
|
- { :ok, _ } = :cowboy.start_http(:http,
|
|
|
- 5000,
|
|
|
- [{:port, 8080}],
|
|
|
- [{ :env, [{:dispatch, dispatch}]}]
|
|
|
- )
|
|
|
+ {:ok, _} = :cowboy.start_http(:http,
|
|
|
+ 5000,
|
|
|
+ [port: 8080],
|
|
|
+ [env: [dispatch: dispatch]])
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -23,11 +17,11 @@ defmodule JsonHandler do
|
|
|
end
|
|
|
|
|
|
def handle(request, state) do
|
|
|
- { :ok, reply } = :cowboy_req.reply(200,
|
|
|
- [{"content-type", "application/json"}],
|
|
|
- Poison.encode!(%{:message => "Hello, World!"}),
|
|
|
- request)
|
|
|
- { :ok, reply, state }
|
|
|
+ {:ok, reply} = :cowboy_req.reply(200,
|
|
|
+ [{"content-type", "application/json"}],
|
|
|
+ Poison.encode!(%{message: "Hello, World!"}),
|
|
|
+ request)
|
|
|
+ {:ok, reply, state}
|
|
|
end
|
|
|
|
|
|
def terminate(_reason, _request, _state) do
|
|
@@ -41,11 +35,11 @@ defmodule PlaintextHandler do
|
|
|
end
|
|
|
|
|
|
def handle(request, state) do
|
|
|
- { :ok, reply } = :cowboy_req.reply(200,
|
|
|
- [{"content-type", "text/plain"}],
|
|
|
- "Hello, World!",
|
|
|
- request)
|
|
|
- { :ok, reply, state }
|
|
|
+ {:ok, reply} = :cowboy_req.reply(200,
|
|
|
+ [{"content-type", "text/plain"}],
|
|
|
+ "Hello, World!",
|
|
|
+ request)
|
|
|
+ {:ok, reply, state}
|
|
|
end
|
|
|
|
|
|
def terminate(_reason, _request, _state) do
|