In the Phoenix Framework, how does one route a custom media type in Accepts?
Phoenix's own code comments indicate the following is all that is necessary—plus a recompile of deps, though the need for that escapes me. But, this seems not to work:
config.exs:
[…]
config :plug, :mimes, %{
"application/vnd.api+json" => ["json-api"]
}
router.ex:
pipeline :api do
plug :accepts, ["json-api"]
end
[…]
scope "/", SomeApp do
pipe_through :api
[…]
some_test.ex:
setup do
conn = conn() |> put_req_header("accept", "application/vnd.api+json")
{:ok, conn: conn}
end
All tests' requests (using conn from setup) receive HTTP 406 responses.
Turns out that the following is inadequate:
% touch deps/plug/mix.exs
% mix deps.compile plug
% mix clean
Instead, as @josé-valim suggests in the question's comments, deleting the entire _build directory did the trick. I went back and forth a few times to be sure, and each time I only touched and deps.compiled, no joy, and each time I removed _build, joy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With