You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Eugene Lazutkin edited this page Jun 17, 2017
·
2 revisions
io() sanitizes queries automatically, both keys and values. But sometimes our URLs may contain variable parameters inline, like that: '/api/clients/11' or '/api/v1/users/Bob%20Smith'.
url() is a function to use with tagged template literals (an ES6 feature). It helps to form a URL by properly sanitizing parameters.
The main API
The function follows standard guidelines, and do not exposes any user-level parameters. It is designed to be used in ES6 environment like that:
importiofrom'heya-io';importurlfrom'heya-io/url';// ...constclient='Bob & Jordan & Co';io.get(url`/api/${client}/details`).then(function(value){// GET /api/Bob%20%26%20Jordan%20%26%20Co/details// ...});
Values of all expressions inside template literals are passed through encodeURIComponent() making them safe for URLs.