Note: Metamark is accessible to all versions of every browser. However, this browser may not support basic Web standards, preventing the display of our site's design details.

Metamark APIs - REST

REST

The easiest interface to use is the rest interface. Simply send a GET or a POST request to http://metamark.net/api/rest/simple with a long_url parameter specifying the url you would like shortened. The long_url parameter should be url encoded.

The resulting page will have one line with the shortened url or in the case of errors (invalid url etc) an error message starting with ERROR:.

A way to get the long_url from a short_url is coming soon.

Perl example

use LWP::Simple qw($ua get);
use URI::Escape qw(uri_escape);

# optionally set the user agent
$ua->agent('MyMetamarkClient/0.1');

my $long_url = uri_escape('http://www.askbjoernhansen.com/?test=foo;bar=baz&kaz=taz');

# use $ua from LWP::Simple to do a post
my $short_url = $ua->post("http://metamark.net/api/rest/simple", { long_url => $long_url })->content;

## You could also use a get request; but using POST is more correct
# my $short_url = get("http://metamark.net/api/rest/simple?long_url=$long_url");

print "$short_url\n";

# Expand the long url from the short url
my $long_url = get("http://metamark.net/api/rest/simple?short_url=$short_url"), "\n";

print "$long_url\n";

Python example

from urllib import urlopen, urlencode
urlopen("http://metamark.net/api/rest/simple", 
urlencode({"long_url":"http://url.to.be.shortened/"})).read()

PHP example


<?php
# SHORTEN
$long_url = urlencode('http://www.cipher-inc.com/');
$short_url = file_get_contents('http://metamark.net/api/rest/simple?long_url='.$long_url);
echo $short_url;
?>

<?php
# LENGTHEN
$short_url = 'http://xrl.us/bhho7x';
$long_url = file_get_contents('http://metamark.net/api/rest/simple?short_url='.$short_url);
echo $long_url;
?>

TCL example

    package require http 2.3
    # SHORTEN
    # shortens a long url [shorten "http://long.url"]
    #
    proc shorten {input} {
      set query [::http::geturl http://metamark.net/api/rest/simple?long_url=${input}]
      set url [lindex [split [::http::data $query] \n] 0]
      return $url
    }
    # LENGTHEN
    # returns the url that a shortened url points to [lengthen "http://xrl.us/foo"]
    #
    proc lengthen {input} {
      set query [::http::geturl http://metamark.net/api/rest/simple?short_url=${input}]
      set url [lindex [split [::http::data $query] \n] 0]
      return $url
    }

Comments and questions to Ask Bjørn Hansen at ask@develooper.com
   © 1999-2024 Develooper LLC