Skip to content

Add option to handle nil values instead of casting to an empty string #7

Description

@clandry94

Hi, I've been using this library through Stripity Stripe and directly in my app to encode maps with lists as application/www-form-urlencoded. One pain point with the library is how it treats nil values in an elixir map when calling params/1. For example, if I have the map that has a nil value

UriQuery.params(%{a: nil})
[{"a", ""}]

Not all APIs treat the empty string as if it were the same as nil, such as Stripe, and it can require additional processing of the returned list from params/1 to make things work correctly. It would be useful if an additional keyword arg could be passed in to control how nil values are handled, such as

UriQuery.params(%{a: nil}, replace_nil: "null")
[{"a", "null"}]

or simpler

UriQuery.params(%{a: nil, b: "c"}, drop_nil: true)
[{"b", "c"}]

If this seems like a good idea, I could take a shot at implementing it and putting up a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions