It can be handy to have a function like this:
function urlEncode(data: object) {
let fields = [];
for (let key in data) {
let value = data[key];
if (value && typeof value === "object") {
value = JSON.stringify(value);
}
let encodedKey = encodeURIComponent(key);
let encodedValue = encodeURIComponent(value);
fields.push(encodedKey + "=" + encodedValue);
}
return fields.join("&");
}
...when dealing with application/x-www-form-urlencoded forms.