Taffrail URL shortener
by taffrail
HTML
<h3>
Short URL
</h3>
<a href="#" id="link" target="_blank"></a>
JavaScript
fetch("https://www.advice.taffrail.com/api/shorten", {
method: "POST",
body: JSON.stringify({
long_url: "https://www.advice.taffrail.com/rule/TFhNUe4x5dNezRP1q5cNY4g/share",
title: "401(k) or Other Workplace Plan"
}),
headers: {
"Content-Type": "application/json",
},
}).then(api => {
return api.json();
}).then(api => {
console.log(api);
// this API returns `advice.link`, but we are migrating to `taffrail.link`
// so you will need to change the value in the response manually. for now.
api.link = api.link.replace("advice.link", "taffrail.link");
document.getElementById("link").innerHTML = api.link;
document.getElementById("link").setAttribute("href", api.link);
});