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. While Metamark generally
is in beta stage, the APIs here are still very much
alpha!. Please send
feedback on how the XML-RPC API work or does not work
for you if you use it. The REST interface is usually much easier to
use.
The previous SOAP interface has been deprecated and since removed, sorry!
Please send examples on how to use the Metamark APIs from other languages (Ruby, PHP, Visual Basic, Objective C / Cocoa, AppleScript, ...)
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
}
The XML-RPC service runs on http://metamark.net/api/xmlrpc. There are only two methods so far, shorten_simple, which takes one parameter (the long url) and returns the shortened url and lookup_simple which does the opposite. Upon errors (invalid url etc) a string "ERROR: error message" will be returned.
use XMLRPC::Lite;
print "Short: ",
XMLRPC::Lite
-> proxy('http://metamark.net/api/xmlrpc')
-> call('shorten_simple', 'http://www.example.com/')
-> result;
print "Long: ",
XMLRPC::Lite
-> proxy('http://metamark.net/api/xmlrpc')
-> call('lookup_simple', 'http://xrl.us/bb')
-> result;
import xmlrpclib
xrl = xmlrpclib.Server('http://metamark.net/api/xmlrpc')
print xrl.shorten_simple('http://www.example.com')
xrl = xmlrpclib.Server('http://metamark.net/api/xmlrpc')
print xrl.lookup_simple('http://xrl.us/qyp')