Using Browser (for demo only)

You can type a Shrinkr API URL on the browser URL address area providing necessary information such as your API Key & the URL that you wish to shrink and initiate your request using the browser. This is just to show how it could be simple to use Shrinkr REST API to shrink url
here is an example, type the following URL -You'll need to use your own API Key-:
  • Using default plain text as result http://rdir.in/api?url=http://shrinkr.codeplex.com/documentation&apikey=YOURAPIKEY
    • In this case the response will be something like this "http://rdir.in/cq"
  • Using JSON format as result http://rdir.in/api?url=http://shrinkr.codeplex.com/documentation&apikey=YOURAPIKEY&format=json
    • In this case the response will be something like this
{
   "shortUrl":"http:\/\/rdir.in\/cq",
   "previewUrl":"http:\/\/rdir.in\/p\/cq",
   "alias":"cq",
   "longUrl":"http:\/\/shrinkr.codeplex.com\/documentation",
   "title":"Shrinkr"
}
  • Using XML format as result http://rdir.in/api?url=http://shrinkr.codeplex.com/documentation&apikey=YOURAPIKEY&format=xml
    • In this case the response will be something like this
<create xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <shortUrl>http://rdir.in/cq</shortUrl>
    <previewUrl>http://rdir.in/p/cq</previewUrl>
    <alias>cq</alias>
    <longUrl>http://shrinkr.codeplex.com/documentation</longUrl>
    <title>Shrinkr</title>
</create>

Using System.Net namespace WebRequest & WebResponse Classes


const string apiKey = "YOUR-GUID-KEY"; //Register at http://rdir.in to get your API Access Key
string url = "http://shrinkr.codeplex.com/documentation";
string format = "text";

//Form Shrinkr API URL, default format is "text". You can supply different format such as "xml" or "json". 
//If you didn't specify format query string at all, plain text will be the default format
string rdirApiUrl = String.Format("http://rdir.in/api?url={0}&apikey={1}&format={2}", url, apiKey, format);

//Create web request
WebRequest request = WebRequest.Create(new Uri(rdirApiUrl));

//Send request and get the response
WebResponse response = request.GetResponse();

string shortUrl;

//Extract content from response stream.
using (var sr = new StreamReader(response.GetResponseStream()))
{
    //Response content is in plain text and will only contain the shortened URL
    shortUrl = sr.ReadToEnd();
}
//Display Result
Console.WriteLine("Your Short URL is: {0} ", shortUrl);

Last edited Apr 23, 2010 at 4:52 PM by mosessaur, version 2

Comments

No comments yet.