how to create tiny url without calling External API (Java)

Vibhav Singh Rohilla picture Vibhav Singh Rohilla · Oct 23, 2015 · Viewed 8.9k times · Source

I need to store URL in QSLITE. I read tinyURL shortens the URL but It requires an API Call to -

http://tinyurl.com/api-create.php

I also read that - "google API services URL shortening" is also used for the same purpose but did not get any working example for this.

My Query is can i obtain shortened URL/ tiny URL without making any external call? Is there any jar that i can use.?

Answer

JB Nizet picture JB Nizet · Oct 23, 2015

You don't seem to understand how tinyurl and similar services work. There is no "equivalent short URL" for any other long URL. The way tinyurl works is that they generate a tiny unique ID for the long URL you submit to the API, and store this association in their database:

12345 -> http://www.foo.com/very/long/url

Then when you go to tinyurl.com/12345, they get the URL associated with the ID 12345, and redirect to that URL.

So, if you want to remember external URLs, there is now way other than storing them as is, or to make an API call to tinyurl to make them generate a short URL for that URL. A simple Java library can't help here. The original long URL must be stored somewhere.