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.
All web services deserves an api or
three. Please send
feedback.
Please send examples on how to use the Metamark APIs from other
languages (Ruby, PHP, Visual Basic, Objective C / Cocoa, AppleScript, ...)
If you use Perl, you might be interested in the WWW::Shorten
package.
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.
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";
from urllib import urlopen, urlencode
urlopen("http://metamark.net/api/rest/simple",
urlencode({"long_url":"http://url.to.be.shortened/"})).read()
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
}