// you're reading...

ColdFusion

ColdFusion: Grab Yourself a 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.

Discussion

6 Responses to “ColdFusion: Grab Yourself a TinyURL”

  1. 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

    Posted by andy matthews | April 20, 2009, 12:05 PM
  2. 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

    Posted by andy matthews | April 20, 2009, 8:05 AM
  3. 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?

    Posted by Lisa Walker | July 29, 2009, 1:55 PM
  4. 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?

    Posted by Lisa Walker | July 29, 2009, 9:55 AM
    • 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.

      Posted by Mike Fleming | July 29, 2009, 7:40 PM

Post a comment

Categories