Function Phoenix.Endpoint.url/0 is undefined or private

Hello,

When I try to use:

IO.inspect Phoenix.Endpoint.url()

it says:

function Phoenix.Endpoint.url/0 is undefined or private

I tried to call another function from Phoenix like IO.inspect Phoenix.json_library() and it works (returns “Jason”).

Why does it say that the function url/0 is undefined or private?

Phoenix.Endpoint.url/0 is a callback.
Try YourAppWeb.Endpoint.url instead.

3 Likes

Thank you. How do these callbacks work actually?

When you use Phoenix.Endpoint, the __using__ macro is invoked (phoenix/lib/phoenix/endpoint.ex at v1.4.10 · phoenixframework/phoenix · GitHub). This function unquotes several other blocks of code (phoenix/lib/phoenix/endpoint.ex at v1.4.10 · phoenixframework/phoenix · GitHub).

Here you can see where url/0 is implemented (phoenix/lib/phoenix/endpoint.ex at v1.4.10 · phoenixframework/phoenix · GitHub).

The callback dictates which functions must be defined when you implement a Behavior. url/0 is one of these functions. Phoenix, of course, provides default implementations for all of these core Behaviors.

4 Likes