I have a plug that abstracts injecting some data in all json responses. I have following plug that uses
register_before_send but its very inefficient. Is there better way I can skip decoding and re-encoding json.
register_before_send(conn, fn conn -> case conn.assigns[:data] do # pattern match is done on data wrt struct data -> res = Poison.decode!(conn.resp_body) |> Map.put(:data, data) |> Poison.encode! resp(conn, conn.status, res) _ -> conn end end)