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 (https://github.com/phoenixframework/phoenix/blob/v1.4.10/lib/phoenix/endpoint.ex#L386). This function unquotes several other blocks of code (https://github.com/phoenixframework/phoenix/blob/v1.4.10/lib/phoenix/endpoint.ex#L393).

Here you can see where url/0 is implemented (https://github.com/phoenixframework/phoenix/blob/v1.4.10/lib/phoenix/endpoint.ex#L558).

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