API

smallr provides an API to access the service by REST request format.
Is supports JSON and XML.

JSON

Use http://smallr.net/json with one parameter url that you want to make it smaller, must be a GET request. It doesn't support the keyword feature.

Request example: http://smallr.net/json?url=http%3A//www.google.pt/search%3Fq%3Djson
(Notice the encoded URL)

Response example: {"status": "ok", "url": "http://smallr.net/85"}

status will return ok on success, else will return an error message.

Python
import simplejson, urllib

url = "http://www.google.pt/search?q=json+python"
response = urllib.urlopen("http://smallr.net/json/?url=" + urllib.quote(url)).read()
json = simplejson.loads(response)
print json
PHP
<?php
$url = "http://www.google.pt/search?q=json+php";
$response = file_get_contents("http://smallr.net/json/?url=" . urlencode($url));
var_dump(json_decode($response));
?>
Perl
use LWP::UserAgent;
use JSON;
use Data::Dumper;
use URI::Escape;

my $ua = LWP::UserAgent->new;
my $json = JSON->new(pretty => 1, delimiter => 0);
my $url = uri_escape("http://www.google.pt/search?q=json+perl");
my $response = $ua->get("http://smallr.net/json/?url=" . $url);
$content = $response->content;
$obj = $json->jsonToObj($content);
print Dumper $obj;
Ruby
require 'rubygems'
require 'net/http'
require 'json/pure'

url = 'http://www.google.pt/search?q=json+ruby'
escaped_url = URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
call = Net::HTTP.get_response(URI.parse("http://smallr.net/json/?url=#{escaped_url}"))
res = JSON.parse(call.body)
puts res['status']
puts res['url']

XML

Request example: http://smallr.net/xml?url=http%3A//www.google.pt/search%3Fq%3Dxml
(Notice the encoded URL)

Response example:

<?xml version="1.0" encoding="utf-8"?>
<smallr>
  <status>ok</status>
  <url>http://smallr.net/85</url>
</smallr>

status will return ok on success, else will return an error message.

PLAIN

Request example: http://smallr.net/api?url=http%3A//www.google.pt/search%3Fq%3Dxml
(Notice the encoded URL)

Response example:

http://smallr.net/85

Will return the generated url on success, else will return an error message.