WPU.IR API

RESTful API Web Service

Shorten

For a long URL, encodes a URL and returns a short one.

Resource URL

http://wpu.ir/api/v1/shortener

Parameters

key – your API key. Sign up for a free key here.
long_url – is a long URL to be shortened (example: http://parsa.ws).

Response

long_url – is an echo back of the long_url request parameter. This may not always be equal to the URL requested. That's because some URL normalization may occur (e.g., due to encoding differences, or case differences in the domain).
short_url – is the actual short URL to be used.
status

  • OK
  • INVALID_URL – invalid long URL address
  • RATE_LIMIT – rate limit exceeded (Usage Limit)
  • AUTH_ERROR – invalid API key
  • INTERNAL_ERROR

Examples

POST http://wpu.ir/api/v1/shortener
key "API Key"
long_url "http://parsa.ws"

If successful, the response will look like:
{
    "long_url": "http://parsa.ws",
    "short_url": "http://wpu.ir/4vfxg",
    "status": "OK"
}

Unsuccessful Status
POST http://wpu.ir/api/v1/shortener
key "API Key"
long_url "test"

Response:
{
    "status": "INVALID_URL"
}

Expand

Given a wpu.ir URL, decodes it and returns back the target URL.

Resource URL

http://wpu.ir/api/v1/expand

Parameters

key – your API key. Sign up for a free key here.
short_url – is a short URL to be expanded (example: http://wpu.ir/4vfxg).

Response

long_url – is an echo back of the long_url request parameter. This may not always be equal to the URL requested. That's because some URL normalization may occur (e.g., due to encoding differences, or case differences in the domain). This long_url will always be functionally identical the request parameter.
short_url – is the actual short URL to be used.
status

  • OK
  • REMOVED - removed from our site
  • MALWARE – detect malware in URL
  • INVALID_URL - invalid short URL address
  • RATE_LIMIT – rate limit exceeded (Usage Limit)
  • AUTH_ERROR – invalid API key
  • INTERNAL_ERROR

Examples

GET http://wpu.ir/api/v1/expand?key={API Key}&short_url=http://wpu.ir/4vfxg
If successful, the response will look like:
{
    "long_url": "http://parsa.ws",
    "short_url": "http://wpu.ir/4vfxg",
    "status": "OK"
}

Unsuccessful Status
GET http://wpu.ir/api/v1/expand?key={API Key}&short_url=http://wpu.ir/4vfxg
Response:
{
    "short_url": "http://wpu.ir/4vfxg",
    "status": "REMOVED"
}

Of course, you could also just fetch http://wpu.ir/4vfxg and inspect the Location header in the response, but using the API has two advantages:

  1. It won't update the short URL's click stats, so you can fetch a bunch of long URLs without worrying about messing up analytics.
  2. If the URL fails to redirect (for example, if we believes it points to malware), you'll get a machine-readable explanation of why.

Example Code

PHP:
$post = [
    'key' => 'API Key',
    'long_url' => 'http://parsa.ws',
];

$ch = curl_init('http://wpu.ir/api/v1/shortener');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);

if ($response) {
    $response = json_decode($response);
    if (json_last_error() === JSON_ERROR_NONE) {
        if ($response->status == 'OK')
            echo $response->short_url;
        else
            echo $response->status;
    }
}