Home » Projects » URL Shortner

URL Shortner

GitHub top language GitHub code size in bytes Python package pages-build-deployment

A python flask application to shorten the URL provided by users whether registered or not.

Live URL: https://vaibhavvikas-url-shortner.herokuapp.com/

Problem Statement

Design a URL shortener that generates a shortened URL for the requested actual URL. The request could come from registered users or could be anonymous. The system should fulfill the following line items.

Stores

  1. Registered user’s details, they are:
    1. user_id
    2. username
    3. name
    4. list of shortened URLs
  2. Shortened URL’s details, they are:
    1. Actual URL
    2. Shortened URL
    3. Creation time
    4. TTL (Time to live)

Features

API Usage

Register User (POST):

$ http://127.0.0.1:5000/user/register
{
    "userid": "vaibhav_vikas",
    "name": "Vaibhav Vikas"
}

Response 200 OK:
{
    "message": "User created successfully",
    "status": "SUCCESS"
}

Registered User shortens an URL (PUT):

$ http://127.0.0.1:5000/user/<userid:vaibhav_vikas>/shortenurl
{
    "url": "google.com",
    "ttl": 60
}

{"url": "google.com"}

Response 200 OK:
{
    "data": {
        "creation_time": "250622222218",
        "owner": "vaibhav_vikas",
        "shortened_url": "ZfcXBmEekiV",
        "ttl": null,
        "url": "youtube.com"
    },
    "message": "URL created successfully",
    "status": "SUCCESS"
}

Get all URLs created by an User (GET):

$ http://127.0.0.1:5000/user/<userid:vaibhav_vikas>/urls

Response 200 OK:
{
    "data": {
        "GeumgANQZMO": {
            "creation_time": "250622222235",
            "owner": "vaibhav_vikas",
            "shortened_url": "GeumgANQZMO",
            "ttl": 180,
            "url": "yahoo.co.in"
        },
        "ZfcXBmEekiV": {
            "creation_time": "250622222218",
            "owner": "vaibhav_vikas",
            "shortened_url": "ZfcXBmEekiV",
            "ttl": null,
            "url": "youtube.com"
        }
    },
    "message": "URLs retrieved successfully for vaibhav_vikas!",
    "status": "SUCCESS"
}

Anonymous user shortens an URL (PUT):

$ http://127.0.0.1:5000/url/shortenurl

{"url":"google.com"}

Response 200 OK:
{
    "data": {
        "creation_time": "250622222828",
        "owner": null,
        "shortened_url": "eZGWXEOanG",
        "ttl": 60,
        "url": "google.com"
    },
    "message": "URL created successfully",
    "status": "SUCCESS"
}

Get the original URL from encoded URL (GET):

$ http://127.0.0.1:5000/url/geturl/<shortened_url:eZGWXEOanG>

Response 200 OK:
{
    "data": {
        "creation_time": "250622222828",
        "owner": null,
        "shortened_url": "eZGWXEOanG",
        "ttl": 60,
        "url": "google.com"
    },
    "message": "URL retrieved successfully",
    "status": "SUCCESS"
}

Miscellaneous get all URLs for debugging (GET):

$ http://127.0.0.1:5000/url/listurls

Response 200 OK
{
    "data": {
        "GeumgANQZMO": {
            "creation_time": "250622222235",
            "owner": "vaibhav_vikas",
            "shortened_url": "GeumgANQZMO",
            "ttl": 180,
            "url": "yahoo.co.in"
        },
        "ZfcXBmEekiV": {
            "creation_time": "250622222218",
            "owner": "vaibhav_vikas",
            "shortened_url": "ZfcXBmEekiV",
            "ttl": null,
            "url": "youtube.com"
        },
        "eZGWXEOanG": {
            "creation_time": "250622222828",
            "owner": null,
            "shortened_url": "eZGWXEOanG",
            "ttl": 60,
            "url": "google.com"
        }
    },
    "message": "URLs retrieved successfully",
    "status": "SUCCESS"
}

Credits

Vaibhav Vikas, 2022