I'm not sure about put_query, as similar effect could be achieved by
URI.merge("http://example.com/?x=1", "?x=2")
пʼятниця, 29 липня 2022 р. о 23:16:10 UTC+3 José Valim пише:
> Elixir v1.14 adds append_query, so we can definitely add put_query. I am
> not super convinced on put_host and friends though. I would love to hear
> everyone's thoughts, but changing the struct should be fine.
>
> On Fri, Jul 29, 2022 at 10:05 PM 'Adam Millerchip' via elixir-lang-core <
> [email protected]> wrote:
>
>> Inspired by this Stack Overflow post:
>>
>> https://stackoverflow.com/questions/49508509/idiom-to-construct-a-uri-with-a-query-string-in-elixir/72223901
>>
>> I thought it might be useful to have helpers to update the struct fields,
>> rather than manipulating the struct directly.
>>
>> Instead of:
>>
>> %URI{uri | host: "example.com"}
>> Map.put(uri, :host, "example.com")
>> etc.
>>
>> We could do:
>>
>> URI.put_host(uri, "example.com")
>>
>> I was thinking that one helper per struct field would be useful. Or maybe
>> only adding a helper for query: `put_query/1` would be an option. Query
>> seems useful, as there is currently no way to programmatically construct a
>> URI with a safely-encoded query string using the `URI` module without
>> manually updating the `query` property (or manually appending the query to
>> a string and calling URI.new again).
>>
>> In the case of `put_query`, it could have two versions: one that puts a
>> string, and one that accepts an enumerable and wraps up encode_query/2.
>>
>> URI.new!("https://example.com") |> URI.put_query(foo: "bar", baz: "qux")
>>
>> Come to think of it, accepting a query enumerable to `new` might even be
>> worth it.
>>
>> I realise this is just syntax sugar, so there might not be desire for
>> such a feature, hence this post. :)
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/elixir-lang-core/666650f2-7a75-4784-b79e-883bff6a3eb8n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/elixir-lang-core/666650f2-7a75-4784-b79e-883bff6a3eb8n%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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/be64b96d-1898-4f4b-86de-a97ed1f949c6n%40googlegroups.com.