elixir-maru / maru

Elixir RESTful Framework
https://maru.readme.io
BSD 3-Clause "New" or "Revised" License
1.32k stars 85 forks source link

Adds scope+namespace support for APIs mounted inside Phoenix #17

Closed adamstrickland closed 8 years ago

adamstrickland commented 8 years ago

Found that using Maru APIs forwarded to by the Phoenix router would get confused when nested inside scope and (or?) namespace clauses. This PR fixes that.


Example problem:

Assume the router.ex:

scope "/api" do
  pipe_through :api

  scope "/mob" do
    forward "/v1", Foo.Apis.Mobile.V1
  end
end

and the API, in /web/apis/mobile/v1.ex:

defmodule Foo.Apis.Mobile.V1 do
  use Maru.Router

  namespace "/bars" do
    get "/", do: conn |> json %{status: "OK"}
  end
end

In this case, the router would not properly put together both the scope and namespace path components. In the above example, the proper, fully-qualified path should be /api/mob/v1/bars, but Maru.Builder.Routers.generate was only producing /bars.

falood commented 8 years ago

Thank you for point it out. I'm thinking this issue these days, and it seems that this PR will NOT solve your problem. This PR requires an argument mount_path and I think this would be read from phoenix routers. I notified that there's to print maru routes forwarded by phoenix router, and I'll do it soon. So, I'll close this PR without merge and improve a way to show maru routes within phoenix, do you think it's feasible?

adamstrickland commented 8 years ago

Yes, sounds good. Thanks.

falood commented 8 years ago

I've push new task maru.routes to master and new version will be release soon.