Phoenix Framework: how to set up custom media type?

In the Phoenix Framework, how can I customize my own media type in Accepts?

my own comments on the Phoenix code indicate that everything that is needed, plus the recompilation of the depot, although the need for this eludes me. But it doesn't seem 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 

Requests for all tests (using the connection from the installation) receive HTTP 406 responses.

+5
source share
1 answer

It 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 comments of the question, deleting the entire _build folder did the trick. I went back and forth several times, and every time I just touched deps.compiled, no joy, and every time I deleted _build, joy.

+7
source

Source: https://habr.com/ru/post/1232284/


All Articles