title: Phoenix: Handle POST request body with Content-Type: application/json
body: <p>I'd like to handle an incoming POST with <code>application/json</code> content type. I am simply trying to return posted JSON as response to test like this:</p>
  
  <p><strong>WebhookController controller</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>router.ex</strong></p>
  
  <pre><code>scope "/webhook", MyApp do
    pipe_through :api
  
    post "/handle", WebhookController, :handle
  end
  </code></pre>
  
  <p>If the incoming post has content type <code>application/json</code>, then body is empty. If the content type is <code>text</code> or <code>text/plain</code>, then body has the content.</p>
  
  <p><strong>What is the right way to parse incoming <code>application/json</code> request body?</strong></p>
  
  <p>I am using Phoenix 1.2</p>