I would like to handle incoming POST with application/json content type. I am just trying to return the published JSON as an answer to the test as follows:
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 mail is of the application/json content type, then the body is empty. If the content type is text or text/plain , then the body has content.
What is the correct way to parse the incoming body of an application/json request?
I am using Phoenix 1.2
source share