@subarna_bhowmik/tinyurl-generator
Version:
Generates a tiny URL
14 lines (13 loc) • 457 B
JavaScript
class TinyURL {
async shorten(url) {
try {
const response = await fetch(`https://tinyurl.com/api-create.php?url=${encodeURIComponent(url)}`);
if (!response.ok) throw new Error('Failed to create tinyurl');
const shortenedUrl = await response.text();
return shortenedUrl;
} catch (error) {
throw new Error('Failed to create tinyurl');
}
}
}
module.exports = TinyURL;