I have two modules: lib/endpoints/v1/base.ex and lib/endpoints/v2/base.ex.
lib/endpoints/v1/base.ex
defmodule Http.Endpoints.V1.Base do
require Logger
use Plug.Router
plug(:match)
plug(:dispatch)
plug(Plug.Logger)
plug(Plug.Parsers, parsers: [:json], json_decoder: Poison)
get "/v1/ping" do
send_resp(conn, 200, "pong!")
end
end
lib/endpoints/v2/base.ex
defmodule Http.Endpoints.V2.Base do
require Logger
use Plug.Router
plug(:match)
plug(:dispatch)
plug(Plug.Logger)
plug(Plug.Parsers, parsers: [:json], json_decoder: Poison)
get "/v2/ping" do
send_resp(conn, 200, "pong! 2")
end
end
My endpoint works correctly if I put in my applications.ex the children
Plug.Cowboy.child_spec(scheme: :http, plug: Http.Endpoints.V1.Base, options: [port: Application.get_env(:http, :port)])
But I would like my application starts all endpoints versions.
I tried to create lib/endpoints.ex with require Http.Endpoints.V1.Base
and require Http.Endpoints.V2.Base
and changed my applications.ex but it did not work.