We recently added append_query, so I am in favor of an append_path. PR
welcome!

On Tue, Dec 13, 2022 at 21:58 aaron....@gmail.com <aaron.ren...@gmail.com>
wrote:

> Hi Everyone,
>
> I have repeatedly run into scenarios when building/testing API clients
> where I want to join a path onto a base url. The base_url could be
> configurable (and maybe read from an environment variable) and the user may
> or may not append a trailing slash to it. Here's the problem I'm trying to
> solve:
>
> Base URI: http://example.com/business_1
> Path to append: /foo
> Desired result: http://example.com/business_1/foo
>
> Base URI: http://example.com/business_1/ # Includes trailing slash
> Path to append: /foo
> Desired result: http://example.com/business_1/foo
>
> Base URI: http://example.com
> Path to append: /foo
> Desired result: http://example.com/foo
>
> Base URI: http://example.com/ # Includes trailing slash
> Path to append: /foo
> Desired result: http://example.com/foo
>
> I don't see a helper to quickly do this and URI.merge/2 replaces the path
> completely. What do you think about `URI.join_path/2`? You should be able
> to do something like this.
>
> iex> URI.join_path("http://example.com/foo/";, "/bar") |> to_string()
> "http://example.com/foo/bar";
>
> I guess it would probably leave any query string variables untouched
>
> iex> URI.join_path("http://example.com/foo/?var1=true";, "/bar") |>
> to_string()
> "http://example.com/foo/bar?var=1";
>
> And maybe it would allow you to join multiple fragments like Path.join/1:
>
> iex> URI.join_path("http://example.com/foo/";, ["bar", "baz"]) |>
> to_string()
> "http://example.com/foo/bar/baz";
>
> What do you think? Is there a better way to do this that I haven't figured
> out?
>
> Aaron Rener
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/3573e832-c6d5-4154-95b4-b857c3850319n%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/3573e832-c6d5-4154-95b4-b857c3850319n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Liv8qUWmSZFXwDQZqZjQ2FK5CWwQZ%2B1ym%3DO%3DUnCSw_GQ%40mail.gmail.com.

Reply via email to