I am coding an Elixir (1.8) + Plug_Cowboy (2.0.2) + Jason (1.1.2) server. From what I am getting from the documentation, once the Plug parser has passed, I should have everything in body_params
. The problem is that accessing conn.body_params
in my case returns %Plug.Conn.Unfetched{aspect: :body_params}
. Check the code below:
defmodule Test.Router do
use Plug.Router
require Logger
plug :match
plug Plug.Parsers, parsers: [:json],
pass: ["application/json", "text/json"],
json_decoder: Jason
plug :dispatch
post "/test" do
Logger.debug inspect(conn.body_params)
conn
|> put_resp_content_type("text/plain")
|> send_resp(204, "Got it")
end
end
Any idea what is going on?
I test this with:
curl -H "Content-Type: text/json" -d "{one: 1, two: 2}" 127.0.0.1:8080/test
I have tried adding :urlencoded
to parsers, or rearranging the plug order, but to no avail.