<url>
- the URL you want to shorten. Example: https://github.com/public-apis/public-apis
Format: text
- Plaintext shortened URL
Python 3.6+
import requests
def shorten(link):
resp = requests.get(f'https://tinyurl.com/api-create.php?url={link}')
return resp.content.decode()
Go
func shorten(link string) (string, error) {
response, err := http.Get("https://tinyurl.com/api-create.php?url=" + link)
if err != nil {
return "", err
}
output, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
response.Body.Close()
return string(output), err
}