Apr
20
by Mike Fleming at 7:03 am (4 Comments) ColdFusion | CFHTTP, cfm, ColdFusion, TinyURL
I have been working on a new application the last few days and one of the requirements was to generate a short URL. There are many different URL shortening services out there today, but I decided to go with one of the original services, TinyURL. Although this service does not provide any sort of API, they do offer a quick and dirty HTTP post method of grabbing a short URL. Using CFHTTP in ColdFusion makes this easy, and only requires a single line of code:
All this does is call the TinyURL post URL and pass in the URL you would like shortened. The post simply returns the text that contains the shortened URL. Now that was to easy! It is a good idea to check the status code of the HTTP call. If a status of 200 is returned, then all is well. If not you can handle the error any way you would like.
andy matthews
April 20, 20098:05 am
About two months ago, I released a ColdFusion library for connecting to a variety of URL shortening services, TinyURL included. Take a look and let me know what you think:
http://andymatthews.net/code/shrinkURL/
I also released an AIR application which ties into the same library:
http://andymatthews.net/code/Shrinkadoo
Mike Fleming
April 20, 20097:51 pm
Andy,
That is a slick little library you have put together there. I’ll definitely check it out and will probably try it out in my app. Thanks!
Lisa Walker
July 29, 20099:55 am
I am looking for something like this, where the visitor can just click on a link that adds the tinyurl to whatever they want.
Now to get it to display the tinyurl link?
Mike Fleming
July 29, 20097:40 pm
I am not sure if I completely understand what you are trying to achieve here? Are you looking to have a link that someone clicks to return a shortened URL of the current page? If so, you can probably use some AJAX code to grab the TinyURL and then pop up the returned link in a modal window or something along those lines.