$ ln -s_ Because the Internet can never have too many redirector services...
 
Home

About

API

Top 10

Including ln-s.net URL creation into your scripts is trivial! All you need to do is issue a simple HTTP request and handle a one-line response.

Point your request at http://ln-s.net/home/api.jsp and provide a parameter called "url". This parameter should be the url you wish to encode, and naturally you'll need to make sure this is properly encoded as a GET or POST parameter per the HTTP protocol.

You will get back a text/plain HTTP response that will contain a 3-digit code and string response, like this:

200 http://ln-s.net/2dW

If you got a 200 code, the string that follows is the redirect URL. Other possible codes include:

  • 503 Try Again (this means there was an error trying to create the entry; wait a few seconds and retry)
  • 400 Missing 'url' parameter (make sure you include in your GET or POST request a parameter called "url")
  • 400 Please enter a URL (your URL parameter was blank)
  • 400 URL scheme not supported (URLs have to start with http://)
  • 400 URL is invalid (self-explanatory)

Here's some example perl code to retrieve a URL:
#!/usr/bin/perl
use LWP::UserAgent;
my($userAgent, $request, $response, $status, $message, $url);

# set up the LWP User Agent and create the request
$userAgent = new LWP::UserAgent;
$request = new HTTP::Request POST => 'http://ln-s.net/home/api.jsp';
$request->content_type('application/x-www-form-urlencoded');

# encode the URL and add it to the url parameter in the request
$url = 'http://web.morons.org/article.jsp?sectionid=1&id=1';
$url = URI::Escape::uri_escape($url);
$request->content("url=$url");

# make the request
$response = $userAgent->request($request);

# handle the response
if ($response->is_success) {
    my $reply = $response->content;
    1 while(chomp($reply));
    ($status, $message) = split(/ /,$reply, 2);
} else {
    ($status, $message) = split(/ /,$response->status_line, 2);
}

print "status: $status\nmessage: $message\n";

In the example above, if $status is 200, the compressed URL is in $message.