API documentation
The u.nu API allows your programs and web sites to request shortened URLs for any address that complies with our terms of service.
Plain-text requests
This is the simplest way to access our service. Your program sends a standard HTTP GET request, with the original (long) URL as a query argument. In response, it receives either a brand-new shortened URL, or an error message explaining what went wrong. The original URL that you supply should be encoded as per standard HTTP specs.
Sample - requesting a shortened URL for “http://www.google.com/”:
http://u.nu/unu-api-simple?url=http%3A%2F%2Fwww.google.com%2F
Response:
http://u.nu/3
If the returned value does not begin with “http”, then it is an error response. There will be a short machine-readable error code, followed by a vertical bar and then a longer human-readable error message.
Sample PHP code:
<?php
$original_url = 'http://www.google.com/';
$request = 'http://u.nu/unu-api-simple?url=' . urlencode($original_url);
$response = file_get_contents($request);
if (substr($request, 0, 4) == 'http')
{
echo "Shortened URL = $response";
}
else
{
list ($error_code, $error_message) = explode('|', $response);
echo "Error = $error_message ($error_code)";
}
?>