Я работаю над API-интерфейсом для эликсира, для которого я использую JaSerializer, но он выдает мне ошибку примерно так же, когда я вызываю post API.
function Poison.encode_to_iodata!/1 is undefined (module Poison is not available)
Но в моем конфигурационном файлеЯ добавил Poison, а также перекомпилировал, используя mime
mix deps.clean mime --build
mix deps.get
Также API, который я вызываю, вставляется в базу данных, но он не отвечает ни на Json, но и выдает мне эту ошибку.
Вот мой конфигурационный файл:
use Mix.Config
config :banking,
ecto_repos: [Banking.Repo]
# Configures the endpoint
config :banking, BankingWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "LMcWbj2QramA5ulI0MZnFobOtrKg/Z2x/gmDl6NwH7hxUbRksPzZjuXwyk8QKGyx",
render_errors: [view: BankingWeb.ErrorView, accepts: ~w(json)],
pubsub: [name: Banking.PubSub, adapter: Phoenix.PubSub.PG2]
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]
config :mime, :types, %{
"application/vnd.api+json" => ["json-api"]
}
config :phoenix, :format_encoders,
"json-api": Poison
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
Это ошибка, которую я получаю
[error] #PID<0.583.0> running BankingWeb.Endpoint (connection #PID<0.582.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /api/banks
** (exit) an exception was raised:
** (UndefinedFunctionError) function Poison.encode_to_iodata!/1 is undefined (module Poison is not available)
Poison.encode_to_iodata!(%{"data" => %{"attributes" => %{"name" => "arvind singh"}, "id" => "19", "type" => "bank"}, "jsonapi" => %{"version" => "1.0"}})
(phoenix) lib/phoenix/controller.ex:729: Phoenix.Controller.__put_render__/5
(phoenix) lib/phoenix/controller.ex:746: Phoenix.Controller.instrument_render_and_send/4
(banking) lib/banking_web/controllers/bank_controller.ex:1: BankingWeb.BankController.action/2
(banking) lib/banking_web/controllers/bank_controller.ex:1: BankingWeb.BankController.phoenix_controller_pipeline/2
(phoenix) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
(banking) lib/banking_web/endpoint.ex:1: BankingWeb.Endpoint.plug_builder_call/2
(banking) lib/plug/debugger.ex:122: BankingWeb.Endpoint."call (overridable 3)"/2
(banking) lib/banking_web/endpoint.ex:1: BankingWeb.Endpoint.call/2
(phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4
(cowboy) /Users/apple/Documents/bankingassignment/banking/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
(cowboy) /Users/apple/Documents/bankingassignment/banking/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3
(cowboy) /Users/apple/Documents/bankingassignment/banking/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Функция Mix Deps
defp deps do
[
{:phoenix, "~> 1.4.9"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 4.0"},
{:ecto_sql, "~> 3.1"},
{:postgrex, ">= 0.0.0"},
{:gettext, "~> 0.11"},
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
{:ja_serializer, github: "vt-elixir/ja_serializer"}
]
end