elm / url

Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
https://package.elm-lang.org/packages/elm/url/latest/
BSD 3-Clause "New" or "Revised" License
74 stars 43 forks source link

add Url.Builder.maybe for building URLs with Maybe String #30

Closed rossvz closed 5 years ago

rossvz commented 5 years ago

This PR is more an interest check than anything else - I've found myself needing to build URLs where some of the query parameters may or may not be added to the final URL, depending on the values. For example, an api with these routes:

GET /products?search=hat GET /products

Means we could have a case where we pass the search value as a Maybe String and use the Url.Builder.maybe like so:

import Url.Builder exposing (absolute, maybe)

absolute ["products"][ maybe "search" (Just hat)  ]
-- "/products?search=hat"
absolute ["products"][ maybe "search" Nothing  ]
-- "/products?="