1
0
Fork 0
mirror of https://github.com/edgurgel/httparrot synced 2025-04-06 00:32:34 -04:00
httparrot/lib/httparrot/get_handler.ex
2019-06-28 09:34:36 +03:00

20 lines
463 B
Elixir

defmodule HTTParrot.GetHandler do
@moduledoc """
Returns GET data.
"""
alias HTTParrot.GeneralRequestInfo
use HTTParrot.Cowboy, methods: ~w(GET HEAD OPTIONS)
def content_types_provided(req, state) do
{[{{"application", "json", []}, :get_json}], req, state}
end
def get_json(req, state) do
{info, req} = GeneralRequestInfo.retrieve(req)
{response(info), req, state}
end
defp response(info) do
info |> JSX.encode!()
end
end