フェニックス アプリケーションを構築しようとしていて、POST 要求を処理しています。リクエスト本文を取得したいのですが、その方法に関するドキュメントが見つからないようです。
いくつかのリバース エンジニアリングを行って、次のコードにたどり着きました。
defmodule MyApp.Controllers.Pages do
use Phoenix.Controller
def post(conn) do
{_, {_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, body, _, _, _, _, _, _}} = conn.adapter
text conn, "#{inspect body}"
end
end
ルーティングあり:
defmodule MyApp.Router do
use Phoenix.Router
post "/test", MyApp.Controllers.Pages, :post
end
もっと良い方法があるはずですよね?
予想される行動:
curl -XPOST localhost:4000/test -d 'this is a test'
$ "this is a test"