mikekelly / hal-browser

An API browser for the hal+json media type
MIT License
839 stars 157 forks source link

Clean up empty query params before interpolating URI templates #39

Closed ismasan closed 10 years ago

ismasan commented 10 years ago

What

This removes keys with empty values from input objects before interpolating them into templated URIs.

Otherwise an input like this:

{
  "foo": 1,
  "bar": ""
}

.. Get's mapped to a URI like this:

host.com?foo=1&bar=

With this change, the case above results in

host.com?foo=1

null or empty string fields will be ignored. Not sure this is desirable for all cases but it makes sense as a rule of thumb.

screenshot 2014-05-02 18 51 57

Why

The same can be achieved by editing the input object manually in the provided text-area and removing the unwanted properties, but that gets annoying when there are too many optional properties.

mikekelly commented 10 years ago

great, thanks!