elstat/lib/api.ex

34 lines
737 B
Elixir
Raw Normal View History

2018-06-12 20:27:37 +00:00
defmodule Elstat.API.CurrentStatus do
2018-06-11 20:42:40 +00:00
require Logger
def init(req0, state) do
data = Elstat.Manager.get_current_state()
req = :cowboy_req.reply(200,
2018-06-12 20:44:19 +00:00
%{"content-type" => "text/json", "Access-Control-Allow-Origin" => "*"},
2018-06-11 20:42:40 +00:00
Poison.encode!(data),
req0
)
{:ok, req, state}
end
end
2018-06-12 20:27:37 +00:00
defmodule Elstat.API.Status do
def init(req0, state) do
status = Elstat.Manager.get_current_state()
graph = Elstat.Manager.get_graph_state()
req = :cowboy_req.reply(200,
2018-06-12 20:44:19 +00:00
%{"content-type" => "text/json", "Access-Control-Allow-Origin" => "*"},
2018-06-12 20:27:37 +00:00
Poison.encode!(%{
status: status,
graph: graph,
}),
req0
)
{:ok, req, state}
end
end