How to get the "path" part of the current URI?

The current url can be retrieved this way:

  Phoenix.Controller.current_url(conn)

How can I get the “path” part of it?

In:

my_domain.com/path1/path2/path3?q=sfdsafdsafds

the

/path1/path2/path3

is what I want to get.

You can use the URI module:

Phoenix.Controller.current_url(conn) |> URI.parse().path
1 Like
Phoenix.Controller.current_path(conn, %{})
2 Likes