Created
April 26, 2024 15:49
-
-
Save jorgevilaca82/68f02f72013acb1e2c1a65361b354ee5 to your computer and use it in GitHub Desktop.
map routes of an external service to use as phoenix routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ExternalAPIRouter do | |
use Phoenix.Router | |
import Plug.Conn | |
import Phoenix.Controller | |
scope "/api/v1" do | |
get("me2", __MODULE__, :me) | |
get("product/:product_id", __MODULE__, :product_detail) | |
end | |
def build_conn() do | |
Phoenix.ConnTest.build_conn() | |
|> then(fn conn -> | |
%Plug.Conn{conn | private: %{phoenix_router_url: "https://api.external.com"}} | |
end) | |
end | |
end | |
ExternalAPIRouter.build_conn() | |
|> ExternalAPIRouter.Helpers.external_api_router_url(:me) | |
ExternalAPIRouter.build_conn() | |
|> ExternalAPIRouter.Helpers.external_api_router_url(:me, [name: "Jorge"]) | |
ExternalAPIRouter.build_conn() | |
|> ExternalAPIRouter.Helpers.external_api_router_url(:product_detail, "prdct12345") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment