Where can I find MsgPack when I POST it to Phoenix server

I am using this SoF link to use MessagePack in my Phoenix app. But within my controller, I cannot find MessagePack in params of my request.

#Here is a snippet of router.ex
scope "/api", AppWeb do
pipe_through :api
post "/", AppController, :request
#and AppWeb.AppController
def request(conn, params) do
IO.inspect params      
|> send_resp(200, "this is a message")

I am using HTTPoison for post request

{:ok, msg} = Msgpax.pack "this is a message"
# Output of above function
# {:ok, [177 | "this is a message"]}
#Msgpax is Elixir library for packing data as MessagePack
HTTPoison.post "http://localhost:4000/api/", msg, [{"Content-Type", "application/octet-stream"}]

Where does MsgPack go when we POST it to a Phoenix server?

You should be able to read it via Plug.Conn.read_body/2 unless it has been already consumed by an earlier plug.

Nailed it. Worked like a charm. Can you tell me how did you come to this observation?

You send the msg as body, so you have to look at the body to retrieve it back, not in the params.

1 Like