Tly URL Shortener

Tly URL Shortener

URL Shorteners

Custom URL shortener for sharing branded links. We're a Bit shorter than the competition. Every short link contributes to new trees being planted. T.LY makes long links look cleaner and easier to share! Add your own Custom Domains to personalize your brand! With over 2,768,211 links shortened and tracking over 3,527,930 clicks, T.LY lets you know where users are coming from. Install our free Extension with over 100,000 users from the extension store to automatically shorten links in one easy click!

Visit API

📚 Documentation & Examples

Everything you need to integrate with Tly URL Shortener

🚀 Quick Start Examples

Tly URL Shortener Javascript Examplejavascript
// Tly URL Shortener API Example
const response = await fetch('https://t.ly/docs', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

Introduction to https://t.ly/docs API

https://t.ly/docs is a public API website that provides developers with a wide range of features to shorten, expand and manage URLs. It provides two endpoints to shorten URLs programmatically, one using RESTful API and the other using JSON-RPC.

In this blog post, we will explore how to use this API making the requests in JavaScript with some possible examples.

Shortening a URL

To shorten a URL using https://t.ly/docs API, we need to send a POST request with a JSON payload to https://api.t.ly/v1/shorten. Here's an example:

const url = 'https://www.example.com'
const apiKey = 'YOUR_API_KEY_HERE'

const form = new FormData();
form.append('url', url);
form.append('apiKey', apiKey);

fetch('https://api.t.ly/v1/shorten', {
  method: 'POST',
  body: form
})
.then(response => response.json())
.then(data => {
  console.log(data)
})
.catch(error => {
  console.error(error)
})

In the example above, we are using fetch to send a POST request to the https://api.t.ly/v1/shorten endpoint with the url and apiKey parameters in a FormData object. The response data is logged to the console.

You will need to replace YOUR_API_KEY_HERE with your actual API key.

Expanding a URL

To expand a URL, we need to send a GET request to https://api.t.ly/v1/expand/[SHORTENED_URL], where [SHORTENED_URL] is the shortened URL returned by the /shorten endpoint. Here's an example:

const shortenedUrl = 'https://t.ly/abcd123'
const apiKey = 'YOUR_API_KEY_HERE'

fetch(`https://api.t.ly/v1/expand/${shortenedUrl}?apiKey=${apiKey}`)
.then(response => response.json())
.then(data => {
  console.log(data)
})
.catch(error => {
  console.error(error)
})

In the example above, we are using fetch to send a GET request to the https://api.t.ly/v1/expand/[SHORTENED_URL] endpoint with the shortenedUrl and apiKey parameters in the URL. The response data is logged to the console.

You will need to replace YOUR_API_KEY_HERE with your actual API key.

Conclusion

In this blog post, we took a look at how to use https://t.ly/docs API to shorten and expand URLs programmatically using JavaScript. The examples provided should give you a good starting point to integrate this API into your own projects.

📊 30-Day Uptime History

Daily uptime tracking showing online vs offline minutes

Jul 2Jul 4Jul 6Jul 8Jul 10Jul 12Jul 14Jul 16Jul 18Jul 20Jul 22Jul 24Jul 26Jul 28Jul 3104008001440Minutes
Online
Offline

Related APIs in URL Shorteners