Shortr API Documentation

Shortr exposes its data via an Application Programming Interface (API), so developers can interact in a programmatic way with the Shortr website. This document is the official reference for that functionality. The current API version is 1.1.0


Getting Started

Here are the topics covered in the Shortr REST API documentation. Also, see API Best Practices


Sections


Request / Response Formats

All Shortr API calls support an optional return format parameter. Note that json is the default response format. but xml, serialized PHP array and a simple txt format is also available.

format=json

All Shortr APIs support jsonp which is the json format with a callback specified, such as:

format=json&callback=callback_method

Here are some examples:


CORS (Cross Origin Resource Sharing)

The Shortr API supports CORS, or Cross Origin Resource Sharing.

Previously, Javascript AJAX requests were restricted to a same domain origin policy. This meant that your website at http://mysite.com/ could not make AJAX requests to http://shortr.tk/, since they were not the same domain. With the introduction of HTML5 and advancements in modern browsers, CORS allows website owners to control who can access data via Javascript AJAX requests. In this way, CORS functions like Flash's Cross Domain Origin Policy. Shortr API supports CORS requests from any domain.

Here is some basic example Javascript to get you started:

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://shortr.tk/api.php?action=create&url=http://shortr.tk");
xhr.onreadystatechange = function() { 
    if(xhr.readyState == 4) { 
        if(xhr.status==200) {
            console.log("CORS works!", xhr.responseText);         
        } else {
            console.log("Oops", xhr);
        }
    } 
}
xhr.send();

You can also read more about CORS here.


Rate Limiting

Shortr currently limits API users to no more than four concurrent connections from a single IP address. Also, Shortr institutes a limit of 140 API requests per hour. Remaining number of API requests, for the hour, is provided in the HTTP header "X-Rate-Limit-Remaining".

While rate limits exist, default limits are more than sufficient for nearly any size site.

Please note that API rate limits reset every hour on the hour. If you are experiencing rate limiting errors, please wait until the top of the hour to resume making API calls. Reset time (in UTC) is provided, as a Unix timestamp, in the HTTP header "X-Rate-Limit-Reset".

To avoid common causes of rate limiting issues, please read API Best Practices.

High-volume users

If you're a high-volume user of the Shortr API, please contact me at ameer1234567890@gmail.com to discuss your options.

When contacting me, include a description of how you are using the Shortr API, which API endpoints you are using, and a current request volume over a 24 hour period.


QR Codes

To generate a QR code, simply append .qrcode to the end of any Shortr link. For example, the following URL: http://shortr.tk/1d.qrcode returns a QR code for the shortr.tk link to this page.


REST API

/api.php?action=create

For a long URL, /api.php?action=create encodes a URL and returns a short one.

Parameters

Notes

Output

Examples


/api.php?action=view

Given a Shortr URL, /api.php?action=view decodes it and returns back the target URL.

Parameters

Notes

Output

Examples


Revision History

Version Date Change
1.0.0 2011-Jun-13 Initial v1 API released.
1.1.0 2011-Aug-20 Serialized php array response format added.