Converts a javascript object to query parameters, then appends this query string
to the current url. String values are used as the query string verbatim.
Set replace to true in the options to replace existing query parameters.
Set omitUndefinedOrNullValues to true in the options to completely omit the key=value pair for undefined or null values.
importQueryAddonfrom"wretch/addons/queryString"
letw = wretch("http://example.com").addon(QueryStringAddon); // url is http://example.com w = w.query({ a:1, b:2 }); // url is now http://example.com?a=1&b=2 w = w.query({ c:3, d: [4, 5] }); // url is now http://example.com?a=1&b=2c=3&d=4&d=5 w = w.query("five&six&seven=eight"); // url is now http://example.com?a=1&b=2c=3&d=4&d=5&five&six&seven=eight w = w.query({ reset:true }, { replace:true }); // url is now http://example.com?reset=true
Note that .query is not meant to handle complex cases with nested objects.
For this kind of usage, you can use wretch in conjunction with other libraries
(like qs).
Converts a javascript object to query parameters, then appends this query string to the current url. String values are used as the query string verbatim.
Set
replacetotruein the options to replace existing query parameters. SetomitUndefinedOrNullValuestotruein the options to completely omit the key=value pair for undefined or null values.Note that .query is not meant to handle complex cases with nested objects.
For this kind of usage, you can use
wretchin conjunction with other libraries (likeqs).