I'd like to handle an incoming POST with application/json content type. I am simply trying to return posted JSON as response to test like this:
WebhookController controller
pipeline :api do
plug :accepts, ["json"]
end
def handle(conn, params) do
{:ok, body, conn} = Plug.Conn.read_body(conn)
json(conn, %{body: body})
end
router.ex
scope "/webhook", MyApp do
pipe_through :api
post "/handle", WebhookController, :handle
end
If the incoming post has content type application/json, then body is empty. If the content type is text or text/plain, then body has the content.
What is the right way to parse incoming application/json request body?
I am using Phoenix 1.2