Simply send a HTTP Post request with the link you want to shorten along with an optional slug if you need, and accessToken if you have one. (optional)
You will get a response back with the short url which you can use however you want, we use 301 redirect which helps you in the SEO :)
// using async function
const res = await fetch('https://bly.to/short', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
long: <YOUR_LONG_URL>, // required
slug: <CUSTOM_SLUG>, // optional
accessToken: <ACCESS_TOKEN>, // optional
})
});
const json = await res.json();
console.log(json);
/*
{
"long": "myawesomewebsite.com",
"shortUrl": "https://bly.to/maw",
"success": true,
}
*/
// using CURL
// curl -XPOST -H "Content-type: application/json" -d '{ "long": "<YOUR_LONG_URL>" }' 'https://bly.to/short'
See this in action on CodePen